Android Question Updated targetSDK, now have permissions issue

Arf

Well-Known Member
Licensed User
Longtime User
I had to fix a small bug in my app, so I thought while I do it I'll update the targetSDK from 22 to 29, as Google requested.
Compiled, worked fine. Then I remember I had not updated my SDM in a while, so did so, and recompiled with android-29 instead of android-25.
App crashes on launch:
java.io.FileNotFoundException: /storage/emulated/0/SpiroConnect Mobile/settings.properties: open failed: EACCES (Permission denied)

So I read a bit about the issues that people have had with moving to android-29 and thought since I don't have muchtime now, just change back to android-25 and update the SDK another day. So I reverted to android-25, cleaned project, compiled and ran, and I get the same EACCES error that I have never seen before.

I wish I never touched it now, but I do need to get a working compilation done today.
So, is the introduction of the EACCES error due to the setting of targetSDK from 22 to 29, or was it because I updated the sdk from 25 to 29?

Many thanks
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
Thanks, I had a read through then I:

1: Kept targetSDK at 29
2: Uninstalled and reinstalled SDK 29 and pointed the android.jar folder to the new file "C:\Program Files (x86)\Android\android-sdk\platforms\android-29\android.jar"
3: Added SetApplicationAttribute (android:requestLegacyExternalStorage, true) to my manifest

Tried again and still "java.io.FileNotFoundException: /storage/emulated/0/SpiroConnect Mobile/settings.properties: open failed: EACCES (Permission denied)"

My app does try access a settings file in DirRootExternal\MyAppFolderName as the first thing it does in the Starter service, before any activities exist. Could this be an issue, in the android cannot ask my permission as there is no activity loaded up yet?

1599060098833.png
 

Attachments

  • 1599060034428.png
    1599060034428.png
    18.8 KB · Views: 210
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
e android.jar folder to the new file "C:\Program Files (x86)\Android\android-sdk\platforms\android-29\android.jar"
It is NEVER a valid path for the SDK.

Programfiles is a restricted folder you should NOT place the SDK into.

Follow the installationinstructions carefully. It will just work.
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
Thanks Don, that makes sense.
I have been using B4A for years with no issue, for some reason the sdk manager has started putting the updates in Program Files all of a sudden. I think I'll completely uninstall it and reinstall the SDK.
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
I followed all the steps, completely reinstalled everying in accordance with the linked instructions, updated to android-29 via B4A SDK updater, but still I get a crash at the same place.
Despite adding the SetApplicationAttribute (android:requestLegacyExternalStorage, true), do I need to add a 'rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)' within an activity before an attempt to access Dir.DirRootExternal is made? As mentioned, the first attempt to access DirRootExternal is in the Starter service befoer any activities are loaded up.
 
Upvote 0

Shelby

Well-Known Member
Licensed User
Longtime User
Perhaps it's redundant, but, did you change the manifest editor to reflect the new SDK 29 level?
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
Ok thanks. So since I need access DirRootExternal this as the very first thing in the Starter Service (where settings are retrieved and logging is started), I imagine I have a problem with rp.CheckAndRequest since I have no activity running yet.

So after some reading it looks like the only way out is:
Use the CanUseOverlays class to allow me to launch a transparent panel activity as first thing in Service Create in my Starter Class, then do a rp.CheckAndRequest for external access

I'll get on with trying that then. If it is a given that use of DirRootExternal is become ever more impossible with android updates, I guess in this update I should also migrate all my files over to DirInternal?

Actually if migrating everything over to DirInternal will make this problem go away in it's entirety it would be best for me to compile this next update as an android-22 project, migrate the files, then do a subsequent android-29 update to get rid of the 'compiled for old version of android'. But that won'r work either as I can't be assured user would run the intermediate all that allows migration before the android-29 version appears on the play store.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Use the CanUseOverlays class to allow me to launch a transparent panel activity as first thing in Service Create in my Starter Class, then do a rp.CheckAndRequest for external access
Only if you want to make things very complicated.

Request the permission when the main activity starts.

I'll get on with trying that then. If it is a given that use of DirRootExternal is become ever more impossible with android updates, I guess in this update I should also migrate all my files over to DirInternal?
True.

this next update as an android-22 project,
No such thing.

I guess that you mean targetSdkVersion. If it is a Google Play app then you must set it to 29.
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
OK thanks for bearing with me, I am making slow progress.

I just remembered that the reason my files are in DirRootExternal is because they need to persist if the user uninstalls the app and reinstalls it, this is essential for my app. I gather there is no internal folder I can use that does not require the permissions and allows persistent data storage, and the SafeDirDefaultExternal would not allow persistent data either?

Second thing, if the user denies the requested permission, it would make the app unusable so in this case would it be be sensible to pop a warning box saying that the app will now exit as this permission is required for use, with an OK button after which the app terminates (or terminates to hte maximum extent allowable)?
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I just remembered that the reason my files are in DirRootExternal is because they need to persist if the user uninstalls the app and reinstalls
I have this situation - but as I don't put apps in the store I am leaving the target at 28 for the time being until Erel answers this query as I need to access the SD Card as well.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I gather there is no internal folder I can use that does not require the permissions and allows persistent data storage, and the SafeDirDefaultExternal would not allow persistent data either?
True.

until Erel answers this query as I need to access the SD Card as well.
Will probably wait for early next week...
 
Upvote 0
Top