Android Question Runtimepermissions and Android 11

slugger

Member
Licensed User
Longtime User
Hi,

I am really struggling with the permissions under Android 11 and possibly later versions.

I am attaching a simple demo, I am never asked for to grant the requested permission (no popup from the operating system) and basically I can't get past the "No Permission 1" toast message.

I have a bigger app which works very well on my Android 6 smartphone but it does not work or crashes if I try to run it on Android 11 as soon as I try to open files.

Any hints?

Thanks in advance.
 

Attachments

  • TestDir.zip
    10.4 KB · Views: 197

agraham

Expert
Licensed User
Longtime User
Firstly you should be using Dialogs2 and the async version of FileDialog and Msgbox.

Secondly you are targeting SDK 30 so PERMISSION_READ_EXTERNAL_STORAGE will be denied. Google has tightened up on direct access to the file store. If you are not putting an app in the Play Store target SDK 28 and it will work as before on Android 11 and 12. If for some reason you need to target SDK 30 but again will not put the app in the Play Store use my Manage External Storage class whose link is the fifth option in this list of options to access files in the latest Android versions.

 
Upvote 2

slugger

Member
Licensed User
Longtime User
Firstly you should be using Dialogs2 and the async version of FileDialog and Msgbox.

Thanks for your answer, FileDialog and MsgBox were in the bigger app I wrote a few years ago, I'll have a look at what you have suggested.

Secondly you are targeting SDK 30 so PERMISSION_READ_EXTERNAL_STORAGE will be denied. Google has tightened up on direct access to the file store.

Do you mean that starting from SDK 30 there is no way to access the external storage for an app that has to be uploaded to the store? :(

I don't need specifically to access the external storage, all I need is access to some kind of folder where the user can upload some files when his/her smartphone is connected to the PC via USB cable or via wireless connection and then my app has to open that file and read it.

Is there a folder still free to be accessed by both the user and the app under SDK 30 despite that Google restrictions mania?
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Do you mean that starting from SDK 30 there is no way to access the external storage for an app that has to be uploaded to the store?
Yes.
Is there a folder still free to be accessed by both the user and the app under SDK 30 despite that Google restrictions mania?
Someone else will have to answer that. I have no apps in the store and just target SDK 28 so I have not bothered to investigate alternative approaches.

However if you connect a PC by USB and allow file transfer File Explorer on the PC can access your File.DirDefaultExternal folder.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Also good to know: after denying the right, Android will likely not even show the user the request anymore. Too many apps have nagged the user to give access, so Google has removed that option for the developers. This is why we can't have nice things.

Uninstall the app first to reset the behavior and show the user the request.
 
Upvote 0
Top