Provide custom text for Android M permission dialog-ThrowExceptions

Exception or error:

Is it possible to provide a custom text for the system dialog which is displayed when the user is asked to grant permission?

How to solve:

No, you can’t customize the text of the dialog, but you can provide an explanation before request the permission. Quoting from

Request Permissions

If your app needs a dangerous permission that was listed in the app
manifest, it must ask the user to grant the permission. Android
provides several methods you can use to request a permission. Calling
these methods brings up a standard Android dialog, which you cannot

Explain why the app needs permissions

In some circumstances, you might want to help the user understand why
your app needs a permission. For example, if a user launches a
photography app, the user probably won’t be surprised that the app
asks for permission to use the camera, but the user might not
understand why the app wants access to the user’s location or
contacts. Before you request a permission, you should consider
providing an explanation to the user. Keep in mind that you don’t want
to overwhelm the user with explanations; if you provide too many
explanations, the user might find the app frustrating and remove it.

One approach you might use is to provide an explanation only if the
user has already turned down that permission request. If a user keeps
trying to use functionality that requires a permission, but keeps
turning down the permission request, that probably shows that the user
doesn’t understand why the app needs the permission to provide that
functionality. In a situation like that, it’s probably a good idea to
show an explanation.

To help find situations where the user might need an explanation,
Android provides a utiltity method,
shouldShowRequestPermissionRationale(). This method returns true if
the app has requested this permission previously and the user denied
the request.


We cannot customize request permission dialog but we can provide user a custom explanation that why we are requesting below is the method with custom explanation

   private void checkForCameraPermission() {
    // Here, thisActivity is the current activity
    if (ContextCompat.checkSelfPermission(this,
            != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
            AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
            alertBuilder.setTitle("Camera permission necessary");
            alertBuilder.setMessage("FITsociety need camera permission to read barcode.");
            alertBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                            new String[]{Manifest.permission.CAMERA},

            AlertDialog alert = alertBuilder.create();
        } else {
            // No explanation needed, we can request the permission.
                    new String[]{Manifest.permission.CAMERA},
            // app-defined int constant. The callback method gets the
            // result of the request.
    } else {

the above method check whether permission is already granted if not then it check if custom explanation is required with this method

ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)

the documentation for this method is here shouldShowRequestPermissionRationale() this method return true only if user deny to permission dialog or user close the permission from the setting of the application if user did so then show alert dialog with custom explanation and proceed further hope it works

Leave a Reply

Your email address will not be published. Required fields are marked *