Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require permission only for older android versions: maxSdkVersion does not work?

I want to some permissions only for older devices for compatibility. So I did some research and found this here:

android:maxSdkVersion
The highest API level at which this permission should be granted to your app. Setting this attribute is useful if the permission your app requires is no longer needed beginning at a certain API level.

For example, beginning with Android 4.4 (API level 19), it's no longer necessary for your app to request the WRITE_EXTERNAL_STORAGE permission when your app wants to write to its own application-specific directories on external storage (the directories provided by getExternalFilesDir()). However, the permission is required for API level 18 and lower. So you can declare that this permission is needed only up to API level 18 with a declaration such as this:

<uses-permission
     android:name="android.permission.WRITE_EXTERNAL_STORAGE"
     android:maxSdkVersion="18" />

I tried to implemented that, but it did not work. So I build up this simple test:

<uses-permission
    android:name="android.permission.WRITE_SMS"
    android:maxSdkVersion="3" />

As far I understand this permission should been only required for devices with the API levels 1-3, but I get this permission request even on a API 18 device. Did I something wrong or is this feature broken?

like image 618
rekire Avatar asked Dec 02 '13 12:12

rekire


People also ask

How do I handle permissions in Android 11?

Starting in Android 11, whenever your app requests a permission related to location, microphone, or camera, the user-facing permissions dialog contains an option called Only this time. If the user selects this option in the dialog, your app is granted a temporary one-time permission.

What is Read_phone_state permission?

android. permission. READ_PHONE_STATE - You must ask the end user to grant this permission.) Allows read only access to the phone's state, and is used to determine the status of any ongoing calls. You need this permission so you can verify that your end user receives a phone call from Telesign.


1 Answers

maxSdkVersion attribute was added in API level 19 (docs should have mentioned that). Ref.:

Introduce maxSdkVersion for <uses-permission>

This way an application can automatically sunset its permission requests when running on later versions of the OS where those permissions are no longer relevant, but may be alarming to the user. A canonical example is WRITE_EXTERNAL_STORAGE, which as of KLP becomes unnecessary for an app to use the external storage volume solely for its own large-data needs, without the need for actual file-system sharing among multiple apps.

Bug 9761041

Change-Id: I60130af3a108fe4a750c356038a1c8cb897e9c8b (missing, can be a Google internal change)

Looks like Android 4.4 was still not named as KK at that time :)

like image 150
ozbek Avatar answered Oct 17 '22 13:10

ozbek