@Override public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException { if (action.equals("storeMeasurement")) { Context ctxt = cordova.getActivity(); (new ClientStatsHelper(ctxt)) .storeMeasurement( data.getString(0), // key data.getString(1), // value data.getString(2)); // ts callbackContext.success(); return true; } else if (action.equals("storeEventNow")) { Context ctxt = cordova.getActivity(); new ClientStatsHelper(ctxt) .storeMeasurement( data.getString(0), // key null, // value String.valueOf(System.currentTimeMillis())); // ts callbackContext.success(); return true; } else { return false; } }
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { this.callbackContext = callbackContext; Log.d("WIFI", action); if(ACTION_START.equals(action)){ PluginResult pgRes = new PluginResult(PluginResult.Status.OK, "Registered"); pgRes.setKeepCallback(true); mWifiManager = (WifiManager) this.cordova.getActivity().getSystemService(Context.WIFI_SERVICE); this.reciever = new BroadcastReceiver() { @Override public void onReceive(Context c, Intent intent) { List<ScanResult> scanResults = mWifiManager.getScanResults(); handleResults(scanResults); } }; this.cordova.getActivity().registerReceiver(this.reciever, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); callbackContext.sendPluginResult(pgRes); Log.d("WIFI", "inside " + action); return true; } else if (ACTION_SCAN.equals(action)){ PluginResult pgRes = new PluginResult(PluginResult.Status.OK, []); pgRes.setKeepCallback(true); mWifiManager = (WifiManager) this.cordova.getActivity().getSystemService(Context.WIFI_SERVICE); mWifiManager.startScan(); callbackContext.sendPluginResult(pgRes); Log.d("WIFI", "inside " + action); return true; } else if (ACTION_STOP.equals(action)){
@Override public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException { this.savedCallbackContext = callbackContext; if (args.optJSONObject(0) != null) { JSONObject obj = args.getJSONObject(0); this.webKey = obj.optString(ARGUMENT_WEB_KEY, null); this.apiKey = obj.optString(ARGUMENT_ANDROID_KEY, null); this.requestOfflineToken = obj.optBoolean(ARGUMENT_OFFLINE_KEY, false); this.setupScopes(obj.optString(ARGUMENT_SCOPES, null)); // possible scope change, so force a rebuild of the client this.mGoogleApiClient = null; } // It's important that we build the GoogleApiClient after setting up scopes so we know which // scopes to request when setting up the google services api client. buildGoogleApiClient(); if (ACTION_IS_AVAILABLE.equals(action)) { final boolean avail = GooglePlayServicesUtil.isGooglePlayServicesAvailable( this.cordova.getActivity().getApplicationContext()) == 0; savedCallbackContext.success("" + avail); } else if (ACTION_LOGIN.equals(action)) { this.trySilentLogin = false; mGoogleApiClient.reconnect(); } else if (ACTION_TRY_SILENT_LOGIN.equals(action)) { this.trySilentLogin = true; mGoogleApiClient.reconnect(); } else if (ACTION_LOGOUT.equals(action)) { try { Plus.AccountApi.clearDefaultAccount(mGoogleApiClient); mGoogleApiClient.disconnect(); // needed in onActivityResult when the connect method below comes back loggingOut = true; buildGoogleApiClient(); mGoogleApiClient.connect(); } catch (IllegalStateException ignore) { } savedCallbackContext.success("logged out"); } else if (ACTION_DISCONNECT.equals(action)) { disconnect(); } else { return false; } return true; }
/** * onConnected is called when our Activity successfully connects to Google Play services. * onConnected indicates that an account was selected on the device, that the selected account has * granted any requested permissions to our app and that we were able to establish a service * connection to Google Play services. */ @Override public void onConnected(Bundle connectionHint) { final Person user = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); // The new cordova permission API's are available since Cordova-Android 5, // so if you're using API level 23 and want to deploy to Android 6, // make sure you're building with Cordova-Android 5 or higher. // .. it was either this or adding an Android Support library. try { Method hasPermissionMethod = cordova.getClass().getMethod("hasPermission", String.class); if (hasPermissionMethod != null) { if (!(Boolean) hasPermissionMethod.invoke(cordova, Manifest.permission.GET_ACCOUNTS)) { Method requestPermissionMethod = cordova .getClass() .getMethod("requestPermission", CordovaPlugin.class, int.class, String.class); requestPermissionMethod.invoke( cordova, this, REQUEST_GET_ACCOUNTS, Manifest.permission.GET_ACCOUNTS); } } } catch (Exception ignore) { } this.email = Plus.AccountApi.getAccountName(mGoogleApiClient); this.result = new JSONObject(); try { result.put("email", email); // in case there was no internet connection, this may be null if (user != null) { result.put("userId", user.getId()); result.put("displayName", user.getDisplayName()); result.put("gender", getGender(user.getGender())); if (user.getImage() != null) { result.put("imageUrl", user.getImage().getUrl()); } if (user.getName() != null) { result.put("givenName", user.getName().getGivenName()); result.put("middleName", user.getName().getMiddleName()); result.put("familyName", user.getName().getFamilyName()); if (user.hasAgeRange()) { if (user.getAgeRange().hasMin()) { result.put("ageRangeMin", user.getAgeRange().getMin()); } if (user.getAgeRange().hasMax()) { result.put("ageRangeMax", user.getAgeRange().getMax()); } } if (user.hasBirthday()) { result.put("birthday", user.getBirthday()); } } } resolveToken(email, result); } catch (JSONException e) { savedCallbackContext.error("result parsing trouble, error: " + e.getMessage()); } }
private void execHelper( final String service, final String action, final String callbackId, final String rawArgs) { CordovaPlugin plugin = getPlugin(service); if (plugin == null) { Log.d(TAG, "exec() call to unknown plugin: " + service); PluginResult cr = new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION); app.sendPluginResult(cr, callbackId); return; } CallbackContext callbackContext = new CallbackContext(callbackId, app); try { long pluginStartTime = System.currentTimeMillis(); boolean wasValidAction = plugin.execute(action, rawArgs, callbackContext); long duration = System.currentTimeMillis() - pluginStartTime; if (duration > SLOW_EXEC_WARNING_THRESHOLD) { Log.w( TAG, "THREAD WARNING: exec() call to " + service + "." + action + " blocked the main thread for " + duration + "ms. Plugin should use CordovaInterface.getThreadPool()."); } if (!wasValidAction) { PluginResult cr = new PluginResult(PluginResult.Status.INVALID_ACTION); callbackContext.sendPluginResult(cr); } } catch (JSONException e) { PluginResult cr = new PluginResult(PluginResult.Status.JSON_EXCEPTION); callbackContext.sendPluginResult(cr); } catch (Exception e) { Log.e(TAG, "Uncaught exception from plugin", e); callbackContext.error(e.getMessage()); } }
@Override public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException { if (action.equals("info")) { String tagName = data.getString(0); String message = data.getString(1); LogManager.i(tagName, message); callbackContext.success(); return true; } else if (action.equals("debug")) { String tagName = data.getString(0); String message = data.getString(1); LogManager.d(tagName, message); callbackContext.success(); return true; } else if (action.equals("error")) { String tagName = data.getString(0); String message = data.getString(1); LogManager.e(tagName, message); callbackContext.success(); return true; } else if (action.equals("warn")) { String tagName = data.getString(0); String message = data.getString(1); LogManager.w(tagName, message); callbackContext.success(); return true; } else if (action.equals("verbose")) { String tagName = data.getString(0); String message = data.getString(1); LogManager.v(tagName, message); callbackContext.success(); return true; } else { return false; } }
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if ("minimize".equals(action)) { try { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); this.cordova.getActivity().startActivity(intent); callbackContext.success(); return true; } catch (Exception e) { return false; } } return false; }
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException { if (requestCode != REQUEST_GET_ACCOUNTS) { return; } for (int i = 0; i < permissions.length; i++) { if (permissions[i].equals(Manifest.permission.GET_ACCOUNTS) && grantResults[i] == PackageManager.PERMISSION_GRANTED) { onConnected(cacheBundle); return; } } savedCallbackContext.error("Must allow Get Account permissions."); }
private void disconnect() { try { Plus.AccountApi.revokeAccessAndDisconnect(mGoogleApiClient) .setResultCallback( new ResultCallback<Status>() { @Override public void onResult(Status status) { // mGoogleApiClient is now disconnected and access has been revoked. // Don't care if it was disconnected already (status != success). buildGoogleApiClient(); savedCallbackContext.success("disconnected"); } }); } catch (IllegalStateException e) { savedCallbackContext.success("disconnected"); } }
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { this.callbackContext = callbackContext; JSONObject options = null; try { options = args.getJSONObject(1); } catch (JSONException e) { // Developer provided no options. Leave options null. } if (ACTION_PLAY_AUDIO.equals(action)) { return playAudio(args.getString(0), options); } else if (ACTION_PLAY_VIDEO.equals(action)) { return playVideo(args.getString(0), options); } else { callbackContext.error("streamingMedia." + action + " is not a supported method."); return false; } }
@Override public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException { if (action.equals("extract")) { try { String id = data.getString(0); String[] serverPremium = { "s210", "s00", "s40", "s10", "s20", "s30", "s50", "s70", "s80", "s90", "s100", "s110", "s120", "s130", "s140", "s160", "s170", "s180", "s190", "s200", "s220", "s230", "s240", "s250", "s260", "s270", "s280", "s290" }; URL url = new URL("http://www.nowvideo.li/mobile/video.php?id=" + id + "&download=2"); URLConnection connection = null; String content = null; connection = url.openConnection(); Scanner scanner = new Scanner(connection.getInputStream()); scanner.useDelimiter("\\Z"); content = scanner.next(); String[] array = content.split("<source src=\"http://"); String link = ""; if (array.length > 2) link = array[2].split("\"")[0]; else link = array[1].split("\"")[0]; String originalServer = link.substring(0, link.indexOf('.')); String restOfLink = link.substring(link.indexOf('.') + 1, link.length()); System.out.println(link); System.out.println(originalServer); System.out.println(restOfLink); String server = originalServer.substring(0, originalServer.length() - 1) + "0"; URL urlVideo = new URL("http://" + server + "." + restOfLink); int responseCode = 0; try { HttpURLConnection huc = (HttpURLConnection) urlVideo.openConnection(); huc.setRequestMethod("HEAD"); huc.setConnectTimeout(2000); responseCode = huc.getResponseCode(); if (responseCode != 200) throw new Exception(); callbackContext.success("http://" + server + "." + restOfLink); } catch (Exception e) { for (String tryServer : serverPremium) { try { urlVideo = new URL("http://" + tryServer + "." + restOfLink); HttpURLConnection huc = (HttpURLConnection) urlVideo.openConnection(); huc.setRequestMethod("HEAD"); huc.setConnectTimeout(2000); responseCode = huc.getResponseCode(); if (responseCode != 200) throw new Exception(); callbackContext.success("http://" + tryServer + "." + restOfLink); } catch (Exception exc) { } } callbackContext.success("http://" + originalServer + "." + restOfLink); } } catch (Exception ex) { callbackContext.error(ex.toString()); } return true; } else { return false; } }
@Override public boolean execute(String action, JSONArray data, CallbackContext callbackContext) { boolean result; Log.v(TAG, "execute: action=" + action); if (INITIALIZE.equals(action)) { try { context = getApplicationContext(); saveConfiguration(context, data.getString(0)); result = true; } catch (JSONException e) { Log.e(TAG, "execute: Got JSON Exception " + e.getMessage()); result = false; callbackContext.error(e.getMessage()); } clearNotificationQueue(context); } else if (REGISTER.equals(action)) { Log.v(TAG, "execute: data=" + data.toString()); try { context = getApplicationContext(); JSONObject jo = data.getJSONObject(0); gWebView = this.webView; Log.v(TAG, "execute: jo=" + jo.toString()); gECB = (String) jo.get("ecb"); gSenderID = (String) jo.get("senderID"); Log.v(TAG, "execute: ECB=" + gECB + " senderID=" + gSenderID); regid = getRegistrationId(getApplicationContext()); if (regid.isEmpty()) { new AsyncRegister().execute(callbackContext); } else { sendJavascript(new JSONObject().put("event", "registered").put("regid", regid)); callbackContext.success(regid); } result = true; } catch (JSONException e) { Log.e(TAG, "execute: Got JSON Exception " + e.getMessage()); result = false; callbackContext.error(e.getMessage()); } if (gCachedExtras != null) { Log.v(TAG, "sending cached extras"); sendExtras(gCachedExtras); gCachedExtras = null; } } else if (ARE_NOTIFICATIONS_ENABLED.equals(action)) { Log.v(TAG, "ARE_NOTIFICATIONS_ENABLED"); final boolean registered = !getRegistrationId(getApplicationContext()).isEmpty(); Log.d(TAG, "areNotificationsEnabled? " + registered); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, registered)); result = true; } else if (UNREGISTER.equals(action)) { GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getApplicationContext()); try { gcm.unregister(); removeRegistrationId(getApplicationContext()); } catch (IOException exception) { Log.d(TAG, "IOException!"); } Log.v(TAG, "UNREGISTER"); result = true; callbackContext.success(); } else { result = false; Log.e(TAG, "Invalid action : " + action); callbackContext.error("Invalid action : " + action); } return result; }
@Override public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException { reader.start(); am.setStreamVolume( AudioManager.STREAM_MUSIC, am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0); this.callbackContext = callbackContext; timedOut = false; Log.w(TAG, action); if (mute) { PluginResult dataResult = new PluginResult(PluginResult.Status.OK, "NOTFOUND"); callbackContext.sendPluginResult(dataResult); return true; } final ACR35Controller self = this; final String loadKeyCommand = "FF 82 00 00 06 %s"; final String authCommand = "FF 86 00 00 05 01 00 %s 60 00"; final String defaultKey = "FF FF FF FF FF FF"; String authKeyCommand = "FF 86 00 00 05 01 00 00 60 00"; if (action.equals("getDeviceId")) { cordova .getThreadPool() .execute( new Runnable() { @Override public void run() { reader.setMute(false); reader.reset( new AudioJackReader.OnResetCompleteListener() { @Override public void onResetComplete(AudioJackReader audioJackReader) { reader.getDeviceId(); } }); } }); } if (action.equals("getDeviceStatus")) { cordova .getThreadPool() .execute( new Runnable() { @Override public void run() { reader.setMute(false); reader.reset( new AudioJackReader.OnResetCompleteListener() { @Override public void onResetComplete(AudioJackReader audioJackReader) { reader.getStatus(); } }); } }); } if (action.equals("readIdFromTag")) { executeAPDUCommands(new byte[][] {hexToBytes("FFCA000000")}); } if (action.equals("readDataFromTag")) { executeAPDUCommands( new byte[][] { hexToBytes(String.format(loadKeyCommand, defaultKey)), hexToBytes(String.format(authCommand, "04")), hexToBytes("FF B0 00 04 10"), hexToBytes("FF B0 00 05 10"), hexToBytes("FF B0 00 06 10"), hexToBytes(String.format(authCommand, "08")), hexToBytes("FF B0 00 08 10"), hexToBytes("FF B0 00 09 10"), hexToBytes("FF B0 00 0A 10"), hexToBytes(String.format(authCommand, "10")), hexToBytes("FF B0 00 10 10"), hexToBytes("FF B0 00 11 10") }); } if (action.equals("writeDataIntoTag")) { try { String dataString = data.get(0).toString(); byte[] dataToWrite = new byte[128]; Arrays.fill(dataToWrite, (byte) 0); byte[] dataBytes = hexToBytes(dataString); System.arraycopy(dataBytes, 0, dataToWrite, 0, dataBytes.length); String dataStringToWrite = bytesToHex(dataToWrite).replaceAll("\\s", ""); String commandString1 = "FF D6 00 04 30" + dataStringToWrite.substring(0, 95); String commandString2 = "FF D6 00 08 30" + dataStringToWrite.substring(96, (96 * 2) - 1); String commandString3 = "FF D6 00 10 20" + dataStringToWrite.substring(96 * 2, (96 * 2 + 64) - 1); Log.w(TAG, dataStringToWrite); executeAPDUCommands( new byte[][] { hexToBytes(String.format(loadKeyCommand, defaultKey)), hexToBytes(String.format(authCommand, "04")), hexToBytes(commandString1), hexToBytes(String.format(authCommand, "08")), hexToBytes(commandString2), hexToBytes(String.format(authCommand, "10")), hexToBytes(commandString3), }); } catch (java.lang.Exception e) { Log.w(TAG, e); } } Calendar calendar = Calendar.getInstance(); // gets a calendar using the default time zone and locale. calendar.add(Calendar.SECOND, timeOut); timer = new Timer(); timer.schedule(new TimeoutClass(reader, self), calendar.getTime()); PluginResult dataResult = new PluginResult(PluginResult.Status.OK, "IGNORE"); dataResult.setKeepCallback(true); callbackContext.sendPluginResult(dataResult); return true; }