Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request permissions based on API level

Beginning in Android 6.0 (API level 23), we can ask permissions at run time. However, according to the docs, all permissions still need to be defined in AndroidManifest.xml so in APIs lower than 23, these permissions will be granted prior to installing the app.

I want to request ACCESS_FINE_LOCATION permission only at runtime - since this is a sensitive permission, requesting it prior to installation without any context will cause a decrease in downloads.

I am targeting my app to API levels 11+, so I wonder whether it is possible not to ask for the ACCESS_FINE_LOCATION permission in older APIs (i.e. not list it in AndroidManifest for APIs older than 23), and only request it for APIs 23+.

Update

For clarification, I want to know whether it is possible to do the following:

AndroidManifest.xml

IF API_LEVEL>=23: {
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
}
ELSE:
{
}
like image 469
Ohad Avatar asked Jul 02 '16 07:07

Ohad


1 Answers

I think you can do this using:

<uses-permission-sdk-23 android:name="string" android:maxSdkVersion="integer" />

You can read more about it in the official documentation: uses-permission-sdk-23

like image 108
Ionut Negru Avatar answered Sep 22 '22 17:09

Ionut Negru