Android M Resolution Issue with Do Not Ask Again Dialog Box

This is an easier way to grant permission using limited directory access, but Dialog will show the "Don't ask again" checkbox. If the user selects Do not ask again and refuses the request, all future requests for this directory from your application will be automatically rejected and the request user interface will not be presented to the user. if the user regrets or hits this flag by mistake, how can I protect the application? The application cannot get permission.

How can we handle this?

+12
source share
6 answers

We should use shouldShowRequestPermissionRationale. Go through this:

private void insertDummyContactWrapper() { int hasWriteContactsPermission = checkSelfPermission(Manifest.permission.WRITE_CONTACTS); if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED) { if (!shouldShowRequestPermissionRationale(Manifest.permission.WRITE_CONTACTS)) { showMessageOKCancel("You need to allow access to Contacts", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { requestPermissions(new String[] {Manifest.permission.WRITE_CONTACTS}, REQUEST_CODE_ASK_PERMISSIONS); } }); return; } requestPermissions(new String[] {Manifest.permission.WRITE_CONTACTS}, REQUEST_CODE_ASK_PERMISSIONS); return; } insertDummyContact(); } 
+1
source

is there any way to change this flag?

The developer cannot change this flag. Otherwise, it would be pointless to have this flag, as the developers would simply ignore it by changing the flag.

However, your question indicates a rather significant lack of access to the directory in a given area: the user has limited ability to change this flag. There seems to be no place in the settings for a specific change in this state, since the user can manually provide the rejected permission at runtime.

On a Nexus 5X with a 7.1 preview, β€œClear Data” will clear this flag, although this has wider effects. On Google Pixel running 7.1 and on Nexus 5X running Android 7.0 this flag will not be reset by anything, even a complete uninstallation of the application.

I filed a bug report about this. I am skeptical that the situation will improve significantly in the short term & - at best, they can fix it, so Data Cleansing works reliably.

+7
source

Open the application permission settings.

You cannot display another dialog box with permissions if the user has checked the "Do not ask again" box.

However, you can help the user and open the application settings, where the user can manually enable the necessary permissions.

To do this, you need to run an intent similar to this:

 public void openAppSettings() { Uri packageUri = Uri.fromParts( "package", getApplicationContext().getPackageName(), null ); Intent applicationDetailsSettingsIntent = new Intent(); applicationDetailsSettingsIntent.setAction( Settings.ACTION_APPLICATION_DETAILS_SETTINGS ); applicationDetailsSettingsIntent.setData( packageUri ); applicationDetailsSettingsIntent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK ); getApplicationContext().startActivity( applicationDetailsSettingsIntent ); } 

Now, to find out when the user unchecked the "Don't ask again" checkbox, this is another question that can be asked with this answer .

+3
source

I think that you need to use the shouldShowRequestPermissionRationale (String) method, it will return false if the user has refused permission and checked "Do not ask again".

What you should do is show a warning explaining to the user why you need permission or implement a backup, for example, disable some functions.

Hope to be helpful.

+2
source
 public class AccessDenied implements View.OnClickListener{ public Dialog dialog; private LinearLayout contentLayout; private Activity context; private EditText password; private String passwordStr; private Runnable doOnAccessPermitted; private int wrongColor = Color.RED, defColor = Color.parseColor("#80000000"); public AccessDenied(Activity con, String pwd) { passwordStr = pwd; context = con; dialog = new Dialog(context, R.style.AnimatedDialog); setCancelable(false); //init the dialog with content view/animations etc. dialog.setContentView(R.layout.access_denied_layout); contentLayout = dialog.findViewById(R.id.layoutIconDialogLinearLayout); password = dialog.findViewById(R.id.accessdeniedlayoutpassword); Button ok = dialog.findViewById(R.id.accessdeniedlayoutok); ok.setOnClickListener(this); //now the dialog is ready } public void setActionOnAccess(Runnable doOnAccess) { doOnAccessPermitted = doOnAccess; } public void setCancelable(boolean set) { dialog.setCancelable(set); } public void show() { dialog.show(); } public void cancel() { dialog.cancel(); } public void setPassword(String pwrd) { passwordStr = pwrd; } public void tryPassword(String tryp) { if(passwordStr.equals(tryp)){ cancel(); if(doOnAccessPermitted != null) doOnAccessPermitted.run(); } } @Override public void onClick(View view) { if(passwordStr.equals(password.getText().toString())) { cancel(); if(doOnAccessPermitted != null) doOnAccessPermitted.run(); }else{ password.getText().clear(); Animation anim = AnimationUtils.loadAnimation(context, R.anim.edittext_shake); anim.setDuration(200); anim.setRepeatCount(5); decView().startAnimation(anim); decView().setBackgroundColor(wrongColor); new android.os.Handler().postDelayed(new Runnable() { @Override public void run() { decView().setBackgroundColor(defColor); } }, 1000); } } private View decView() { return password; } } 
+1
source

I created a method to capture all user actions using concatenated if ... else if ... else, and it worked well for me.
First, to determine whether there was a permission or a denial "This request was also checked , I combined the permission status check with mustShowRequestPermissionRationale (Manifest.permission.SEND_SMS).
Then, to determine if only permission without without the DL5 β€œDo not ask again” permission was denied, I used permission status checking. Below is a snippet:

 @RequiresApi(api = Build.VERSION_CODES.M) //this is added for API lower than 23 public void myPermissionRationale(){ //This checks both permission status and the Don't ask again check box if (ContextCompat.checkSelfPermission(this,Manifest.permission.SEND_SMS ) == PackageManager.PERMISSION_DENIED && !shouldShowRequestPermissionRationale(Manifest.permission.SEND_SMS)) { //open app permission settings here for instance } //only checks permission status then shows permission request pop up again else if (ContextCompat.checkSelfPermission(this,Manifest.permission.SEND_SMS ) == PackageManager.PERMISSION_DENIED){ // Request the permission ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS}, 10); } } 
0
source

Source: https://habr.com/ru/post/1259902/


All Articles