My app asks the user for camera permission. If the user rejects the permission, he is asked for permission at the restart again. This time, "never ask again" checkbox is shown to the user. If the user selects the never ask again checkbox, the application can never ask for permission. It is OK. The problem is that my phone does never forget this selection, it remembers this selection. I removed the application, cleared all data but nothing works.
When I delete the application and reinstall it, the application can still never ask for permission. I opened Settings-> Application Settings -> Then I gave necessary permission to my application manually. It is ok. Then, I delete and reinstall it again. But the application can still never ask for permission. I do not want to give my app permission manually at each installation. How to reset the selection of "never ask again" checkbox.
if (Build.VERSION.SDK_INT >= 23)
{
int hasPermission = ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA);
if (hasPermission != PackageManager.PERMISSION_GRANTED)
{
if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA))
{
getErrorDialog("You need to allow Camera permission." +
"\nIf you disable this permission, You will not able to add attachment.", MainActivity.this, true).show();
}
return;
}
}
public AlertDialog.Builder getErrorDialog(String message, Context context, final boolean isFromCamera) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setTitle(getString(R.string.app_name)).setMessage(message);
alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (Build.VERSION.SDK_INT >= 23) {
if(isFromCamera){
requestPermissions(new String[]{Manifest.permission.CAMERA},
REQUEST_CODE_ASK_PERMISSIONS_CAMERA);
}else {
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
REQUEST_CODE_ASK_PERMISSIONS_EXTERNAL_STORAGE);
}
}
}
});
return alertDialog;
}