Android M Runtime Permissions: Detecting User Selection of "Never Ask Again"

Nov 23, 2025 · Programming · 9 views · 7.8

Keywords: Android Permissions | Runtime Permissions | Never Ask Again Detection

Abstract: This article provides an in-depth analysis of Android M's runtime permission mechanism, focusing on how to detect when users select the "Never Ask Again" option using the shouldShowRequestPermissionRationale method. It covers permission request workflows, user interaction scenarios, implementation strategies, and best practices for handling permission denials and guiding users to app settings.

Overview of Runtime Permission Mechanism

Android M (6.0) introduced the runtime permission model, shifting from traditional install-time permission grants to dynamic permission requests during app usage. This enhancement gives users greater control over their privacy data while requiring developers to adopt new permission handling strategies.

Evolution of Permission Request Dialogs

The permission request dialog underwent significant changes during Android M's developer preview phases. While the initial version included a "Never Ask Again" checkbox, this option was removed in Preview 2. Subsequent permission requests after initial denial display the "Never Ask Again" option, balancing user experience with permission control requirements.

Core Method for Detecting "Never Ask Again" Status

The Activity.shouldShowRequestPermissionRationale(String) method is crucial for detecting user selection of the "Never Ask Again" option. Its behavior follows this logic:

Permission Handling Implementation Code

The following code demonstrates complete permission request and result handling workflow:

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == REQUEST_PERMISSION) {
        for (int i = 0, len = permissions.length; i < len; i++) {
            String permission = permissions[i];
            if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
                boolean showRationale = shouldShowRequestPermissionRationale(permission);
                if (!showRationale) {
                    // User selected "Never Ask Again"
                    handleNeverAskAgain(permission);
                } else {
                    // User denied without selecting "Never Ask Again"
                    showPermissionRationale(permission);
                }
            }
        }
    }
}

private void handleNeverAskAgain(String permission) {
    // Guide user to app settings page
    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    Uri uri = Uri.fromParts("package", getPackageName(), null);
    intent.setData(uri);
    startActivityForResult(intent, REQUEST_PERMISSION_SETTING);
}

private void showPermissionRationale(String permission) {
    // Display permission explanation dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Permission Explanation")
           .setMessage("This feature requires the permission to function properly")
           .setPositiveButton("Retry", (dialog, which) -> requestPermissions(new String[]{permission}, REQUEST_PERMISSION))
           .setNegativeButton("Cancel", null)
           .show();
}

User Guidance Strategies

When detecting "Never Ask Again" selection, applications should provide clear guidance:

  1. For non-essential features: Disable related functionality and offer alternatives
  2. For core features: Guide users to system settings to manually enable permissions
  3. Provide clear status indications about feature limitations due to missing permissions

Best Practice Recommendations

Based on practical development experience, adopt these permission handling strategies:

Conclusion

Android M's runtime permission mechanism presents both challenges and opportunities for application development. By properly utilizing the shouldShowRequestPermissionRationale method, developers can accurately identify user permission selection states and deliver smarter, more user-friendly permission management experiences. Appropriate permission handling strategies not only enhance user experience but also build user trust in applications.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.