Android Question EACCES (Permission denied) when trying to write from service module

kostefar

Active Member
Licensed User
Longtime User
Dear All,

I´ve moved a ton of stuff to a service module so that internet and file operations can also execute while app is paused. This worked perfectly before when they were in the main activity, but now I get this error:

B4X:
java.io.FileNotFoundException: /storage/emulated/0/Android/data/mobi.test.test/files/vv/backgrounds.zip: open failed: EACCES (Permission denied)

stopping at this line:

B4X:
File.Copy (File.DirAssets , "backgrounds.zip",rp.GetSafeDirDefaultExternal("") & "/" & usernametmp,"backgrounds.zip")

I have "Dim rp As RuntimePermissions" in the service module, and in the manifest I have:

B4X:
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23"/>

which was also there before.

Are there special concerns for writing to storage when it´s called from a service module?

Thanks in advance!
 

kostefar

Active Member
Licensed User
Longtime User
No.

Don't set targetSdkVersion to 23 unless you want to use runtime permissions: https://www.b4x.com/android/forum/threads/67689

Indeed I want to use runtimepermissions and targetsdkversion 23, otherwise it won´t work on Marshmallow. As mentioned, it worked before when it was all in the main activity and all set up following the guide lines in the link you sent:

1. Use RuntimePermissions.GetSafeDirDefaultExternal("") instead of File.DirDefaultExternal. The parameter passed is an optional subfolder that will be created under the default folder.

2. Add this code to the manifest editor:
Code:
AddManifestText(
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)

This is (also) in my manifest:

B4X:
AddManifestText(
<uses-permission
  android:name="android.permission.WRITE_EXTERNAL_STORAGE"
  android:maxSdkVersion="18" />
)

The only difference is that file handling is now taking place in a service module - no longer in the main activity.
Is there maybe anything which should be added here in the service module:
B4X:
#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region

Edit: Something else must be wrong. Just tried doing this from activity_create in the main activity, and the same happens so after all not related to the type of module inside which it´s running...
 
Last edited:
Upvote 0

kostefar

Active Member
Licensed User
Longtime User
That's not correct.

There is no relation between targetSdkVersion and the supported versions.


Oh really? Good that I can have this misunderstanding corrected. But why is it then that as soon as I set targetsdkversion to 22, I get this error, when compiling for a 6.0 device:

Failure [INSTALL_FAILED_PERMISSION_MODEL_DOWNGRADE]
 
Upvote 0

kostefar

Active Member
Licensed User
Longtime User
You need to first uninstall the app. If you already submitted it to Google Play then you will not be able to change it.

Wow, thanks! I´m so glad I know now that it´s all about the already installed app causing this error! Still wondering though why I get the Access Denied errors, but I may just stop using runtimepermissions and go back to the old way.

Thanks again!
 
Upvote 0
Top