Java Code Examples for androidx.core.app.ActivityCompat#shouldShowRequestPermissionRationale()

The following examples show how to use androidx.core.app.ActivityCompat#shouldShowRequestPermissionRationale() . 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: MainActivity.java    From MusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
public void requestPermission() {
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE
            }, MY_PERMISSIONS_WRITE_STORAGE);

        } else {
            ActivityCompat.requestPermissions(this,
                    new String[]{
                            Manifest.permission.WRITE_EXTERNAL_STORAGE
                    },
                    MY_PERMISSIONS_WRITE_STORAGE);

        }
    } else onPermissionGranted();
}
 
Example 2
Source File: GroupChatFragment.java    From SendBird-Android with MIT License 6 votes vote down vote up
private void requestStoragePermissions() {
    if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
            Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        // Provide an additional rationale to the user if the permission was not granted
        // and the user would benefit from additional context for the use of the permission.
        // For example if the user has previously denied the permission.
        Snackbar.make(mRootLayout, "Storage access permissions are required to upload/download files.",
                Snackbar.LENGTH_LONG)
                .setAction("Okay", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                PERMISSION_WRITE_EXTERNAL_STORAGE);
                    }
                })
                .show();
    } else {
        // Permission has not been granted yet. Request it directly.
        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                PERMISSION_WRITE_EXTERNAL_STORAGE);
    }
}
 
Example 3
Source File: OpenChatFragment.java    From SendBird-Android with MIT License 6 votes vote down vote up
private void requestStoragePermissions() {
    if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
            Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        // Provide an additional rationale to the user if the permission was not granted
        // and the user would benefit from additional context for the use of the permission.
        // For example if the user has previously denied the permission.
        Snackbar.make(mRootLayout, "Storage access permissions are required to upload/download files.",
                Snackbar.LENGTH_LONG)
                .setAction("Okay", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                PERMISSION_WRITE_EXTERNAL_STORAGE);
                    }
                })
                .show();
    } else {
        // Permission has not been granted yet. Request it directly.
        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                PERMISSION_WRITE_EXTERNAL_STORAGE);
    }
}
 
Example 4
Source File: MainActivity.java    From here-android-sdk-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    switch (requestCode) {
        case REQUEST_CODE_ASK_PERMISSIONS: {
            for (int index = 0; index < permissions.length; index++) {
                if (grantResults[index] != PackageManager.PERMISSION_GRANTED) {

                    /*
                     * If the user turned down the permission request in the past and chose the
                     * Don't ask again option in the permission request system dialog.
                     */
                    if (!ActivityCompat
                            .shouldShowRequestPermissionRationale(this, permissions[index])) {
                        Toast.makeText(this, "Required permission " + permissions[index]
                                               + " not granted. "
                                               + "Please go to settings and turn on for sample app",
                                       Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(this, "Required permission " + permissions[index]
                                + " not granted", Toast.LENGTH_LONG).show();
                    }
                }
            }

            setupMapFragmentView();
            break;
        }
        default:
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}
 
Example 5
Source File: AbsBaseActivity.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == PERMISSION_REQUEST) {
        for (int grantResult : grantResults) {
            if (grantResult != PackageManager.PERMISSION_GRANTED) {
                if (ActivityCompat.shouldShowRequestPermissionRationale(AbsBaseActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                    //User has deny from permission dialog
                    Snackbar.make(getSnackBarContainer(), getPermissionDeniedMessage(),
                            Snackbar.LENGTH_INDEFINITE)
                            .setAction(R.string.action_grant, view -> requestPermissions())
                            .setActionTextColor(ThemeStore.accentColor(this))
                            .show();
                } else {
                    // User has deny permission and checked never show permission dialog so you can redirect to Application settings page
                    Snackbar.make(getSnackBarContainer(), getPermissionDeniedMessage(),
                            Snackbar.LENGTH_INDEFINITE)
                            .setAction(R.string.action_settings, view -> {
                                Intent intent = new Intent();
                                intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                                Uri uri = Uri.fromParts("package", AbsBaseActivity.this.getPackageName(), null);
                                intent.setData(uri);
                                startActivity(intent);
                            })
                            .setActionTextColor(ThemeStore.accentColor(this))
                            .show();
                }
                return;
            }
        }
        hadPermissions = true;
        onHasPermissionsChanged(true);
    }
}
 
Example 6
Source File: AbsBaseActivity.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == PERMISSION_REQUEST) {
        for (int grantResult : grantResults) {
            if (grantResult != PackageManager.PERMISSION_GRANTED) {
                if (ActivityCompat.shouldShowRequestPermissionRationale(AbsBaseActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                    //User has deny from permission dialog
                    Snackbar.make(getSnackBarContainer(), getPermissionDeniedMessage(),
                            Snackbar.LENGTH_INDEFINITE)
                            .setAction(R.string.action_grant, view -> requestPermissions())
                            .setActionTextColor(ThemeStore.accentColor(this))
                            .show();
                } else {
                    // User has deny permission and checked never show permission dialog so you can redirect to Application settings page
                    Snackbar.make(getSnackBarContainer(), getPermissionDeniedMessage(),
                            Snackbar.LENGTH_INDEFINITE)
                            .setAction(R.string.action_settings, view -> {
                                Intent intent = new Intent();
                                intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                                Uri uri = Uri.fromParts("package", AbsBaseActivity.this.getPackageName(), null);
                                intent.setData(uri);
                                startActivity(intent);
                            })
                            .setActionTextColor(ThemeStore.accentColor(this))
                            .show();
                }
                return;
            }
        }
        hadPermissions = true;
        onHasPermissionsChanged(true);
    }
}
 
Example 7
Source File: MainActivity.java    From here-android-sdk-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    switch (requestCode) {
        case REQUEST_CODE_ASK_PERMISSIONS: {
            for (int index = 0; index < permissions.length; index++) {
                if (grantResults[index] != PackageManager.PERMISSION_GRANTED) {

                    /*
                     * If the user turned down the permission request in the past and chose the
                     * Don't ask again option in the permission request system dialog.
                     */
                    if (!ActivityCompat
                            .shouldShowRequestPermissionRationale(this, permissions[index])) {
                        Toast.makeText(this, "Required permission " + permissions[index]
                                               + " not granted. "
                                               + "Please go to settings and turn on for sample app",
                                       Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(this, "Required permission " + permissions[index]
                                + " not granted", Toast.LENGTH_LONG).show();
                    }
                }
            }

            setupMapFragmentView();
            break;
        }
        default:
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}
 
Example 8
Source File: ScannerFragment.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Scan for 5 seconds and then stop scanning when a BluetoothLE device is found then lEScanCallback
 * is activated This will perform regular scan for custom BLE Service UUID and then filter out.
 * using class ScannerServiceParser
 */
private void startScan() {
	// Since Android 6.0 we need to obtain Manifest.permission.ACCESS_FINE_LOCATION to be able to scan for
	// Bluetooth LE devices. This is related to beacons as proximity devices.
	// On API older than Marshmallow the following code does nothing.
	if (ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
		// When user pressed Deny and still wants to use this functionality, show the rationale
		if (ActivityCompat.shouldShowRequestPermissionRationale(requireActivity(), Manifest.permission.ACCESS_FINE_LOCATION) && permissionRationale.getVisibility() == View.GONE) {
			permissionRationale.setVisibility(View.VISIBLE);
			return;
		}

		requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_PERMISSION_REQ_CODE);
		return;
	}

	// Hide the rationale message, we don't need it anymore.
	if (permissionRationale != null)
		permissionRationale.setVisibility(View.GONE);

	adapter.clearDevices();
	scanButton.setText(R.string.scanner_action_cancel);

	final BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
	final ScanSettings settings = new ScanSettings.Builder()
			.setLegacy(false)
			.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).setReportDelay(1000).setUseHardwareBatchingIfSupported(false).build();
	final List<ScanFilter> filters = new ArrayList<>();
	filters.add(new ScanFilter.Builder().setServiceUuid(uuid).build());
	scanner.startScan(filters, settings, scanCallback);

	scanning = true;
	handler.postDelayed(() -> {
		if (scanning) {
			stopScan();
		}
	}, SCAN_DURATION);
}
 
Example 9
Source File: OdysseyMainActivity.java    From odyssey with GNU General Public License v3.0 5 votes vote down vote up
private void requestPermissionExternalStorage() {
    // ask for permissions
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.READ_EXTERNAL_STORAGE)) {

            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
            View layout = findViewById(R.id.drawer_layout);
            if (layout != null) {
                Snackbar sb = Snackbar.make(layout, R.string.permission_request_snackbar_explanation, Snackbar.LENGTH_INDEFINITE);
                sb.setAction(R.string.permission_request_snackbar_button, view -> ActivityCompat.requestPermissions(OdysseyMainActivity.this,
                        new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        PermissionHelper.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE));
                // style the snackbar text
                TextView sbText = sb.getView().findViewById(com.google.android.material.R.id.snackbar_text);
                sbText.setTextColor(ThemeUtils.getThemeColor(this, R.attr.odyssey_color_text_accent));
                sb.show();
            }
        } else {

            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    PermissionHelper.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
        }
    }
}
 
Example 10
Source File: PermissionRequester.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
/**
 * @return true for there no need to request, do your work it now.
 * false for do in {@link androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, String[], int[])}
 */
public static boolean request(final Activity activity, final String permission, String rationale, final int requestCode) {
    if (!(activity instanceof ActivityCompat.OnRequestPermissionsResultCallback)) {
        throw new IllegalStateException("The Activity must implement ActivityCompat.OnRequestPermissionsResultCallback");
    }

    if (ActivityCompat.checkSelfPermission(activity, permission)
            == PackageManager.PERMISSION_GRANTED) {
        return true;
    }

    if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
        new AlertDialog.Builder(activity)
                .setMessage(rationale)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        requestPermissions(activity, new String[]{permission}, requestCode);
                    }
                }).setNegativeButton(android.R.string.cancel, null)
                .show();
    } else {
        return requestPermissions(activity, new String[]{permission}, requestCode);
    }

    return false;
}
 
Example 11
Source File: MicrophoneConfigureActivity.java    From haven with GNU General Public License v3.0 5 votes vote down vote up
private void startMic () {
    String permission = Manifest.permission.RECORD_AUDIO;
    int requestCode = 999;
    if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {

            //This is called if user has denied the permission before
            //In this case I am just asking the permission again
            ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);

        } else {

            ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);
        }
    } else {

        try {
            microphone = MicrophoneTaskFactory.makeSampler(this);
            microphone.setMicListener(this);
            microphone.execute();
        } catch (MicrophoneTaskFactory.RecordLimitExceeded e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
 
Example 12
Source File: MainActivity.java    From location-samples with Apache License 2.0 5 votes vote down vote up
private void requestPermissions() {
    boolean shouldProvideRationale =
            ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.ACCESS_FINE_LOCATION);

    // Provide an additional rationale to the user. This would happen if the user denied the
    // request previously, but didn't check the "Don't ask again" checkbox.
    if (shouldProvideRationale) {
        Log.i(TAG, "Displaying permission rationale to provide additional context.");
        Snackbar.make(
                findViewById(R.id.activity_main),
                R.string.permission_rationale,
                Snackbar.LENGTH_INDEFINITE)
                .setAction(R.string.ok, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        // Request permission
                        ActivityCompat.requestPermissions(MainActivity.this,
                                new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                                REQUEST_PERMISSIONS_REQUEST_CODE);
                    }
                })
                .show();
    } else {
        Log.i(TAG, "Requesting permission");
        // Request permission. It's possible this can be auto answered if device policy
        // sets the permission in a given state or the user denied the permission
        // previously and checked "Never ask again".
        ActivityCompat.requestPermissions(MainActivity.this,
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                REQUEST_PERMISSIONS_REQUEST_CODE);
    }
}
 
Example 13
Source File: MainActivity.java    From here-android-sdk-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    switch (requestCode) {
        case REQUEST_CODE_ASK_PERMISSIONS: {
            for (int index = 0; index < permissions.length; index++) {
                if (grantResults[index] != PackageManager.PERMISSION_GRANTED) {

                    /*
                     * If the user turned down the permission request in the past and chose the
                     * Don't ask again option in the permission request system dialog.
                     */
                    if (!ActivityCompat
                            .shouldShowRequestPermissionRationale(this, permissions[index])) {
                        Toast.makeText(this, "Required permission " + permissions[index]
                                               + " not granted. "
                                               + "Please go to settings and turn on for sample app",
                                       Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(this, "Required permission " + permissions[index]
                                + " not granted", Toast.LENGTH_LONG).show();
                    }
                }
            }

            setupMapFragmentView();
            break;
        }
        default:
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}
 
Example 14
Source File: CustomDeviceActivity.java    From voice-quickstart-android with MIT License 5 votes vote down vote up
private void requestPermissionForMicrophone() {
    if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.RECORD_AUDIO)) {
        Snackbar.make(coordinatorLayout,
                "Microphone permissions needed. Please allow in your application settings.",
                Snackbar.LENGTH_LONG).show();
    } else {
        ActivityCompat.requestPermissions(
                this,
                new String[]{Manifest.permission.RECORD_AUDIO},
                MIC_PERMISSION_REQUEST_CODE);
    }
}
 
Example 15
Source File: MapsAppActivity.java    From maps-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Requests the {@link Manifest.permission#ACCESS_COARSE_LOCATION}
 * permission. If an additional rationale should be displayed, the user has
 * to launch the request from a SnackBar that includes additional
 * information.
 */

private void requestLocationPermission() {
	// Permission has not been granted and must be requested.
	if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {

		// Provide an additional rationale to the user if the permission was
		// not granted
		// and the user would benefit from additional context for the use of
		// the permission.
		// Display a SnackBar with a button to request the missing
		// permission.
		Snackbar.make(mLayout, "Location access is required to display the map.", Snackbar.LENGTH_INDEFINITE)
				.setAction("OK", new View.OnClickListener() {
					@Override
					public void onClick(View view) {
						// Request the permission
						ActivityCompat.requestPermissions(MapsAppActivity.this,
								new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
								PERMISSION_REQUEST_LOCATION);
					}
				}).show();

	} else {
		// Request the permission. The result will be received in
		// onRequestPermissionResult().
		ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
				PERMISSION_REQUEST_LOCATION);
	}
}
 
Example 16
Source File: Permissions.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean shouldShouldPermissionRationale(String permission) {
  return ActivityCompat.shouldShowRequestPermissionRationale(activity, permission);
}
 
Example 17
Source File: Location.java    From UberClone with MIT License 4 votes vote down vote up
private void requestPermissions(){
    Boolean contextProvider=ActivityCompat.shouldShowRequestPermissionRationale(activity, permissionFineLocation);

    if (contextProvider)Message.message(activity.getApplicationContext(), Messages.RATIONALE);
    permissionRequest();
}
 
Example 18
Source File: PermissionServiceActivity.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
@Override public void requestAccessToCamera(@Nullable Action0 toRunWhenAccessIsGranted,
    @Nullable Action0 toRunWhenAccessIsDenied) {
  int hasPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
  if (hasPermission != PackageManager.PERMISSION_GRANTED) {
    this.toRunWhenAccessToFileSystemIsGranted = toRunWhenAccessIsGranted;
    this.toRunWhenAccessToFileSystemIsDenied = toRunWhenAccessIsDenied;

    if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
      Logger.getInstance()
          .v(TAG, "showing rationale and requesting permission to access camera");

      showMessageOKCancel(R.string.camera_access_permission_request_message,
          new SimpleSubscriber<GenericDialogs.EResponse>() {

            @Override public void onNext(GenericDialogs.EResponse eResponse) {
              super.onNext(eResponse);
              if (eResponse != GenericDialogs.EResponse.YES) {
                if (toRunWhenAccessToFileSystemIsDenied != null) {
                  toRunWhenAccessToFileSystemIsDenied.call();
                }
                return;
              }

              ActivityCompat.requestPermissions(PermissionServiceActivity.this, new String[] {
                  Manifest.permission.CAMERA
              }, PERMISSIONS_REQUEST_ACCESS_CAMERA);
            }
          });
      return;
    }

    ActivityCompat.requestPermissions(PermissionServiceActivity.this, new String[] {
        Manifest.permission.CAMERA
    }, PERMISSIONS_REQUEST_ACCESS_CAMERA);
    Logger.getInstance()
        .v(TAG, "requesting permission to access camera");
    return;
  }
  Logger.getInstance()
      .v(TAG, "already has permission to access camera");
  if (toRunWhenAccessIsGranted != null) {
    toRunWhenAccessIsGranted.call();
  }
}
 
Example 19
Source File: GrantPermissionActivity.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
private boolean canShowRationale(Context context, boolean forceGrant) {
    showRequestWriteSettings = false;
    //showRequestAccessNotificationPolicy = false;
    showRequestDrawOverlays = false;
    showRequestReadExternalStorage = false;
    showRequestReadPhoneState = false;
    showRequestWriteExternalStorage = false;
    showRequestReadCalendar = false;
    showRequestReadContacts = false;
    showRequestAccessCoarseLocation = false;
    showRequestAccessFineLocation = false;

    if (permissions != null) {
        whyPermissionType = new boolean[20][100];

        for (Permissions.PermissionType permissionType : permissions) {
            if (permissionType.permission.equals(Manifest.permission.WRITE_SETTINGS)) {
                showRequestWriteSettings = Permissions.getShowRequestWriteSettingsPermission(context) || forceGrant;
                whyPermissionType[0][permissionType.type] = true;
            }
            /*if (permissionType.permission.equals(Manifest.permission.ACCESS_NOTIFICATION_POLICY)) {
                showRequestAccessNotificationPolicy = Permissions.getShowRequestAccessNotificationPolicyPermission(context) || forceGrant;
                whyPermissionType[1][permissionType.type] = true;
            }*/
            if (permissionType.permission.equals(Manifest.permission.SYSTEM_ALERT_WINDOW)) {
                showRequestDrawOverlays = Permissions.getShowRequestDrawOverlaysPermission(context) || forceGrant;
                whyPermissionType[2][permissionType.type] = true;
            }
            if (permissionType.permission.equals(Manifest.permission.READ_EXTERNAL_STORAGE)) {
                showRequestReadExternalStorage = ActivityCompat.shouldShowRequestPermissionRationale(this, permissionType.permission) || forceGrant;
                whyPermissionType[3][permissionType.type] = true;
            }
            if (permissionType.permission.equals(Manifest.permission.READ_PHONE_STATE)) {
                showRequestReadPhoneState = ActivityCompat.shouldShowRequestPermissionRationale(this, permissionType.permission) || forceGrant;
                whyPermissionType[4][permissionType.type] = true;
            }
            if (permissionType.permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                showRequestWriteExternalStorage = ActivityCompat.shouldShowRequestPermissionRationale(this, permissionType.permission) || forceGrant;
                whyPermissionType[6][permissionType.type] = true;
            }
            if (permissionType.permission.equals(Manifest.permission.READ_CALENDAR)) {
                showRequestReadCalendar = ActivityCompat.shouldShowRequestPermissionRationale(this, permissionType.permission) || forceGrant;
                whyPermissionType[7][permissionType.type] = true;
            }
            if (permissionType.permission.equals(Manifest.permission.READ_CONTACTS)) {
                showRequestReadContacts = ActivityCompat.shouldShowRequestPermissionRationale(this, permissionType.permission) || forceGrant;
                whyPermissionType[8][permissionType.type] = true;
            }
            if (permissionType.permission.equals(Manifest.permission.ACCESS_COARSE_LOCATION)) {
                showRequestAccessCoarseLocation = ActivityCompat.shouldShowRequestPermissionRationale(this, permissionType.permission) || forceGrant;
                whyPermissionType[12][permissionType.type] = true;
            }
            if (permissionType.permission.equals(Manifest.permission.ACCESS_FINE_LOCATION)) {
                showRequestAccessFineLocation = ActivityCompat.shouldShowRequestPermissionRationale(this, permissionType.permission) || forceGrant;
                whyPermissionType[13][permissionType.type] = true;
            }
            if (Build.VERSION.SDK_INT >= 29) {
                if (permissionType.permission.equals(Manifest.permission.ACCESS_BACKGROUND_LOCATION)) {
                    showRequestAccessBackgroundLocation = ActivityCompat.shouldShowRequestPermissionRationale(this, permissionType.permission) || forceGrant;
                    whyPermissionType[14][permissionType.type] = true;
                }
            }
        }
    }

    return (showRequestWriteSettings ||
            showRequestReadExternalStorage ||
            showRequestReadPhoneState ||
            showRequestWriteExternalStorage ||
            showRequestReadCalendar ||
            showRequestReadContacts ||
            showRequestAccessCoarseLocation ||
            showRequestAccessFineLocation ||
            showRequestAccessBackgroundLocation ||
            //showRequestAccessNotificationPolicy ||
            showRequestDrawOverlays);
}
 
Example 20
Source File: PermissionsUtils.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static boolean shouldShowRequestForLocationPermission(Activity activity) {
    return (ActivityCompat.shouldShowRequestPermissionRationale(activity,
            Manifest.permission.ACCESS_FINE_LOCATION)
            || ActivityCompat.shouldShowRequestPermissionRationale(activity,
            Manifest.permission.ACCESS_COARSE_LOCATION));
}