Java Code Examples for androidx.fragment.app.Fragment#requestPermissions()
The following examples show how to use
androidx.fragment.app.Fragment#requestPermissions() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PermUtil.java From PixImagePicker with Apache License 2.0 | 6 votes |
public static void checkForCamaraWritePermissions(final Fragment fragment, WorkFinish workFinish) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { workFinish.onWorkFinish(true); } else { List<String> permissionsNeeded = new ArrayList<String>(); final List<String> permissionsList = new ArrayList<String>(); if (!addPermission(permissionsList, Manifest.permission.CAMERA, fragment.getActivity())) permissionsNeeded.add("CAMERA"); if (!addPermission(permissionsList, Manifest.permission.WRITE_EXTERNAL_STORAGE, fragment.getActivity())) permissionsNeeded.add("WRITE_EXTERNAL_STORAGE"); if (permissionsList.size() > 0) { fragment.requestPermissions(permissionsList.toArray(new String[permissionsList.size()]), REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS); } else { workFinish.onWorkFinish(true); } } }
Example 2
Source File: UiUtils.java From tindroid with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) static void requestAvatar(@Nullable Fragment fragment) { if (fragment == null) { return; } final Activity activity = fragment.getActivity(); if (activity == null || activity.isFinishing() || activity.isDestroyed()) { return; } if (!isPermissionGranted(activity, android.Manifest.permission.READ_EXTERNAL_STORAGE)) { fragment.requestPermissions(new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, READ_EXTERNAL_STORAGE_PERMISSION); } else { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); fragment.startActivityForResult(Intent.createChooser(intent, fragment.getString(R.string.select_image)), ACTIVITY_RESULT_SELECT_PICTURE); } }
Example 3
Source File: Permission.java From image-zoom-view with Apache License 2.0 | 5 votes |
public static boolean askPermissionForFragment(Activity activity,Fragment fragment, String permission, int requestCode){ int permissionId = ContextCompat.checkSelfPermission(activity.getApplicationContext(), permission); if (permissionId != PackageManager.PERMISSION_GRANTED) { fragment.requestPermissions(new String[]{permission},requestCode); }else { return true; } return false; }
Example 4
Source File: PermissionsUtils.java From SAI with GNU General Public License v3.0 | 5 votes |
private static boolean checkAndRequestPermissions(Fragment f, String[] permissions, int requestCode) { if (Build.VERSION.SDK_INT < 23) return true; for (String permission : permissions) { if ((ActivityCompat.checkSelfPermission(f.requireContext(), permission)) == PackageManager.PERMISSION_DENIED) { f.requestPermissions(permissions, requestCode); return false; } } return true; }
Example 5
Source File: PermissionHelper.java From zapp with MIT License | 5 votes |
public static boolean writeExternalStorageAllowed(Fragment fragment) { if (ActivityCompat.checkSelfPermission(fragment.requireContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { fragment.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE_WRITE_EXTERNAL_STORAGE); return false; } else { return true; } }
Example 6
Source File: ImportExportPrefs.java From AndroidAPS with GNU Affero General Public License v3.0 | 5 votes |
static void verifyStoragePermissions(Fragment fragment) { int permission = ContextCompat.checkSelfPermission(fragment.getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE); if (permission != PackageManager.PERMISSION_GRANTED) { // We don't have permission so prompt the user fragment.requestPermissions(PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE); } }
Example 7
Source File: PermissionHelper.java From openScale with GNU General Public License v3.0 | 5 votes |
public static boolean requestReadPermission(final Fragment fragment) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (fragment.getContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { fragment.requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_ACCESS_READ_STORAGE); } else { return true; } } return false; }
Example 8
Source File: PermissionHelper.java From openScale with GNU General Public License v3.0 | 5 votes |
public static boolean requestWritePermission(final Fragment fragment) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (fragment.getContext().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { fragment.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_ACCESS_WRITE_STORAGE); } else { return true; } } return false; }
Example 9
Source File: Permissions.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
private static void requestPermissions(@NonNull Fragment fragment, int requestCode, String... permissions) { fragment.requestPermissions(filterNotGranted(fragment.getContext(), permissions), requestCode); }
Example 10
Source File: Permissions.java From deltachat-android with GNU General Public License v3.0 | 4 votes |
private static void requestPermissions(@NonNull Fragment fragment, int requestCode, String... permissions) { fragment.requestPermissions(filterNotGranted(fragment.getContext(), permissions), requestCode); }
Example 11
Source File: PermissionsUtil.java From edx-app-android with Apache License 2.0 | 4 votes |
@TargetApi(Build.VERSION_CODES.M) public static void requestPermissions(int requestCode, @NonNull String[] permissions, @NonNull Fragment fragment) { fragment.requestPermissions(permissions, requestCode); }