public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException { if (!action.equals("navigation")) { return false; } this.option = NavigationOption.parseArgs(args); this.callbackContext = callbackContext; if (!hasPermisssion()) { PermissionHelper.requestPermissions(this, 0, permissions); } else { this.showNavigationView(); } PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); return true; }
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (!action.equals("getCurrentPosition") && !action.equals("watchPosition")) { return false; } if (!hasPermisssion()) { int requestCode = UUID.randomUUID().hashCode(); PermissionHelper.requestPermissions(this, requestCode, permissions); permissionCallback.put(requestCode, new CallbackContextHolder(action.equals("getCurrentPosition"), callbackContext)); } else { this.initClient(action.equals("getCurrentPosition"), callbackContext); } PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); return true; }
private void promptForRecord() { if(PermissionHelper.hasPermission(this, permissions[WRITE_EXTERNAL_STORAGE]) && PermissionHelper.hasPermission(this, permissions[RECORD_AUDIO])) { this.startRecordingAudio(recordId, FileHelper.stripFileProtocol(fileUriStr)); } else if(PermissionHelper.hasPermission(this, permissions[RECORD_AUDIO])) { getWritePermission(WRITE_EXTERNAL_STORAGE); } else { getMicPermission(RECORD_AUDIO); } }
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { LOG.d(TAG, "We are entering execute"); context = callbackContext; if(action.equals("getPermission")) { if(hasPermisssion()) { PluginResult r = new PluginResult(PluginResult.Status.OK); context.sendPluginResult(r); return true; } else { PermissionHelper.requestPermissions(this, 0, permissions); } return true; } return false; }
private void promptForRecord() { if (PermissionHelper.hasPermission(this, permission)) { Log.i(TAG,"开启唤醒"); wakeup = EventManagerFactory.create(getApplicationContext(), "wp"); wakeup.registerListener(wakeupListener); Map<String, Object> params = new LinkedHashMap<String, Object>(); params.put(com.baidu.speech.asr.SpeechConstant.APP_ID, "10099877"); params.put(com.baidu.speech.asr.SpeechConstant.ACCEPT_AUDIO_VOLUME, false); params.put(com.baidu.speech.asr.SpeechConstant.WP_WORDS_FILE, "assets:///WakeUp.bin"); String json = null; // 这里可以替换成你需要测试的json json = new JSONObject(params).toString(); wakeup.send(com.baidu.speech.asr.SpeechConstant.WAKEUP_START, json, null, 0, 0); } else { getMicPermission(0); } }
/** * Check saveImage arguments and app permissions * * @param args JSON Array of args * @param callbackContext callback id for optional progress reports * * args[0] filePath file path string to image file to be saved to gallery */ private void saveImageToGallery(JSONArray args, CallbackContext callback) throws JSONException { this.filePath = args.getString(0); this.callbackContext = callback; Log.d("SaveImage", "SaveImage in filePath: " + filePath); if (filePath == null || filePath.equals("")) { callback.error("Missing filePath"); return; } if (PermissionHelper.hasPermission(this, WRITE_EXTERNAL_STORAGE)) { Log.d("SaveImage", "Permissions already granted, or Android version is lower than 6"); performImageSave(); } else { Log.d("SaveImage", "Requesting permissions for WRITE_EXTERNAL_STORAGE"); PermissionHelper.requestPermission(this, WRITE_PERM_REQUEST_CODE, WRITE_EXTERNAL_STORAGE); } }
public boolean hasPermisssion() { for (String p : permissions) { if (!PermissionHelper.hasPermission(this, p)) { return false; } } return true; }
public boolean hasPermisssion() { for(String p : permissions) { if(!PermissionHelper.hasPermission(this, p)) { return false; } } return true; }
private boolean calendarPermissionGranted(String... types) { if (Build.VERSION.SDK_INT < 23) { return true; } for (final String type : types) { if (!PermissionHelper.hasPermission(this, type)) { return false; } } return true; }
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { this.callbackContext = callbackContext; this.params = args.getJSONObject(0); if (action.equals("getPictures")) { maximumImagesCount = 9; desiredWidth = 0; desiredHeight = 0; quality = 100; if (this.params.has("maximumImagesCount")) { maximumImagesCount = this.params.getInt("maximumImagesCount"); } if (this.params.has("width")) { desiredWidth = this.params.getInt("width"); } if (this.params.has("height")) { desiredHeight = this.params.getInt("height"); } if (this.params.has("quality")) { quality = this.params.getInt("quality"); } if(!PermissionHelper.hasPermission(this, permissions[0])) { PermissionHelper.requestPermissions(this, PICK_ALBUM_SEC, permissions); } else { this.getPictures(maximumImagesCount, desiredWidth,desiredHeight,quality); } return true; } return false; }
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if(!PermissionHelper.hasPermission(this, READ_SMS)) { PermissionHelper.requestPermission(this, SEARCH_REQ_CODE, READ_SMS); callbackContext.success("PLUGIN_PERMISSION_REQUESTED"); return true; } else if (action.equals("checkText")) { String message = args.getString(0); this.checkText(message, callbackContext); return true; } return false; }
private void promptForMic() { if(PermissionHelper.hasPermission(this, permissions[RECORD_AUDIO])) { this.startRecognition(); } else { getMicPermission(); } }
@Override public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals("openFileNative")) { callback = callbackContext; if (!PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { PermissionHelper.requestPermission(this, permissionRequestCode, Manifest.permission.READ_EXTERNAL_STORAGE); return true; } final JSONObject params = args.getJSONObject(0); if (!params.has("file") || params.has("file") && params.getString("file").length() == 0) { callback.error("File Parameter is missing"); return true; } final String fileToOpen = params.getString("file"); progressTitle = (params.has("progressTitle") && params.getString("progressTitle").length() > 0) ? params.getString("progressTitle") : "Open File"; cordova.getActivity().runOnUiThread(new Runnable() { public void run() { try { URI uri = new URI(fileToOpen); if (uri.isAbsolute() && uri.getScheme().equalsIgnoreCase("market")) { context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(fileToOpen))); callback.success(); } else { new DownloadAndOpenTask().execute(uri); } } catch (URISyntaxException e) { callback.error("Error while opening file \"" + fileToOpen + "\"."); } } }); return true; } else { return false; } }
/** * 判断是否有对应权限 */ public boolean hasPermisssion() { for(String p : permissions) { if(!PermissionHelper.hasPermission(this, p)) { return false; } } return true; }
public boolean hasPermisssion() { for (final String p : permissions) { if (!PermissionHelper.hasPermission(this, p)) { return false; } } return true; }
public void requestPermissions(int requestCode) { PermissionHelper.requestPermissions(this, requestCode, permissions); }
private void getReadPermission(String rawArgs, int action, CallbackContext callbackContext) { int requestCode = pendingRequests.createRequest(rawArgs, action, callbackContext); PermissionHelper.requestPermission(this, requestCode, Manifest.permission.READ_EXTERNAL_STORAGE); }
private void getWritePermission(String rawArgs, int action, CallbackContext callbackContext) { int requestCode = pendingRequests.createRequest(rawArgs, action, callbackContext); PermissionHelper.requestPermission(this, requestCode, Manifest.permission.WRITE_EXTERNAL_STORAGE); }
private boolean hasReadPermission() { return PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE); }
private boolean hasWritePermission() { return PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE); }