Write permission for Android <11

I have an app that writes to a shared folder (/Music). It works fine in API 30, but in Android 9 it doesn't move files to /Music.

Do I need to ask for WRITE permissions specifically for older android phones, and if so, what is the best current method? Do I just ask for the write permission and ignore the message in android 11 (permission not found)? Or is there some kind of check I could do? Thank you very much

In the Screen1 blocks there is a PlatformVersion block. You can use this as a test condition as to whether to ask for permission or not on first run, depending on the Android version of your device. You may need to run a list because some of the numbers are not straightforward e.g. 4.2.2

If this doesn't work then the FileTools extension and the KIO4_base64 extension offer a block that returns the API, but this might always returns 30 or higher (futureproofing post here...)

Both appear to work as required, tested with companion 2.61u on android 10 (29) and android 11 (30)

1 Like

Nice. The PlatformVersion block works great. One note: I needed to strip any decimals to be able to compare it numerically. Because it returns something like "6.0.1" but in other phone it returns simply "11". My blocks (working good):

But why do you want that WRITE permission is requested on Android 10 devices?

Note: Asking for WRITE permission on Android 10 is only possible because AI2 has decided to continue to declare requestLegacyExternalStorage (even after the targetSdkVersion = 30 update) in the Manifest.

But there is no longer any component that can store something in external storage. So that would only make sense if you want to save something there by means of an extension. But then files are saved under different paths under Android 10 and 11 (Android 10: in the external storage and Android 11: in the ASD). However, if this is not desired, it makes no sense to request WRITE permission under Android 10, as this permission is not required there.

So I need to declare requestLegacyExternalStorage for android <11? How do I do that?

No, read my answer again.
You should only ask for WRITE permission on devices with Android ≤ 9.

1 Like

Oh ok Thanks :slight_smile:

Please tell me, am I doing this right?

to simplify this, you could add an if statement in the Initialize event like this

if android version < 10
then AskForPermission WriteExternalStorage
else AskForPermission ReadExternalStorage

because WriteExternalStorage includes ReadExternalStorage


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.



Exactly. You were faster than me again. :wink:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.