Home » Android » android – Marshmallow Permissions not working for TargetVersion below 23

android – Marshmallow Permissions not working for TargetVersion below 23

Posted by: admin June 15, 2020 Leave a comment

Questions:

My project is a long running project. I had set the target version as 10, 4 years back. I cant change the target version to 23, since I am using httpImageCache and also having issues with UI’s. My problem is, when Marshmallow released I tried to integrate Marshmallow with targetVersion 10,

 int returnedPermission = ContextCompat.checkSelfPermission(MyActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);

this function is always returing ‘0’ if I manually ON or Off storage permission from App Settings page. Can any one please help me?

How to&Answers:

As @Commonware has already given the answer, but here I am adding more detail to the question which might help you.
As per the official android developer site:

  • If the device is running Android 5.1 or lower, or your app’s target
    SDK is 22 or lower
    : If you list a dangerous permission in your
    manifest, the user has to grant the permission when they install the app; if they do not grant the permission, the system does not install the app at all.

  • If the device is running Android 6.0 or higher, and your app’s target
    SDK is 23 or higher: The app has to list the permissions in the
    manifest, and it must request each dangerous permission it needs
    while the app is running. The user can grant or deny each permission,
    and the app can continue to run with limited capabilities even if the
    user denies a permission request.

As your target SDK is 10, application will run perfectly like previous. Anyway please note that user still can revoke a permission after that..!!! Although Android 6.0 warn the user when they try to do that but they can revoke anyway.

Above statement is taken from official android developer site.

Answer:

Can any one please help me?

Delete that code, as it is useless for you. If your targetSdkVersion is below 23, you cannot find out whether or not the user revoked permissions.

Answer:

use PermissionChecker.checkSelfPermission()

when targetSdkVersion <= 22,you also can use requestPermission()