2

I have managed the Run-time permission from onResume() on my BaseActivity. When I start my application, a runtime permission dialog opens that time without taking any action on the dialog I goes to app setting and take actions on permissions. Now when I again resume the application there is still the previous dialog shown.

So if I already allowed the permission then what should I do with the dialog because it's still showing?

MLavoie
  • 9,671
  • 41
  • 36
  • 56
Rashpal Singh
  • 633
  • 3
  • 13
  • Can you please explain better what you are looking for? – xdevs23 Mar 22 '16 at 11:47
  • Your condition is wrong show code how you check – Ajay Pandya Mar 22 '16 at 11:51
  • 2
    "I am asking for permission in onResume of activity" -- I would not recommend that as a pattern. – CommonsWare Mar 22 '16 at 11:54
  • you need to checkpermission only at the time you need to acces the Resource which you are requesting permission to – Logic Mar 22 '16 at 11:59
  • i have managed the Run-time permission from onResume on my Base Activity. when i start my application, a runtime permission dialog opens that time but without taking action on that dialog I goes to setting menu and take actions on permissions. Now I again resume the application but here still the previous dialog shown. please help – Rashpal Singh Mar 23 '16 at 04:38
  • Try this it may be work http://stackoverflow.com/a/41221852/5488468 – Bipin Bharti Jan 03 '17 at 10:55

3 Answers3

3

It is an Android OS issue. I have also faced same issue and found OS issue.

Archana Pareta
  • 198
  • 1
  • 9
1

It is not a good idea to request permission in the onResume method. You should only request permission when needed. However, you can use this code to fix the issue:

boolean permissionRequested = false;

@Override
protected void onResume() {
    super.onResume();
    if (Build.VERSION.SDK_INT > 22) {
        if (getPackageManager().checkPermission(Manifest.permission.CAMERA, getPackageName()) == PackageManager.PERMISSION_GRANTED) {
            permissionRequested = false;
            Toast.makeText(this, "Permission Granted", Toast.LENGTH_SHORT).show();
        } else {
            if (permissionRequested) {
                permissionRequested = false;
                Toast.makeText(this, "Permission Denied", Toast.LENGTH_SHORT).show();
            } else {
                permissionRequested = true;
                requestPermissions(new String[] { Manifest.permission.CAMERA }, 100);
            }
        }
    } else {
        Toast.makeText(this, "Permission Granted", Toast.LENGTH_SHORT).show();
    }
}
-1

Check if you have the permission in onResume - and only show the dialog if you get a negative result

ligi
  • 39,001
  • 44
  • 144
  • 244