Android Question Runtime Permissions

GaryK4

Member
Licensed User
Longtime User
I have read a lot, but I still cannot get the WRITE_EXTERNAL_STORAGE permission to work.
I have a simple FTP test program that works with android:targetSdkVersion="22", but not 26.

The following code give me an error with 26, but not 22:
java.io.FileNotFoundException: /storage/emulated/0/Golf_Match/Test.txt (Permission denied)
B4X:
FTP.DownloadFile("Test.txt", False, File.DirRootExternal, "Golf_Match/Test.txt")

My manifest looks like the following:

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26"/>
<uses-permission
  android:name="android.permission.WRITE_EXTERNAL_STORAGE"
  android:maxSdkVersion="19" />
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
   
'---------- Permissions ------------------
AddPermission(android.permission.READ_EXTERNAL_STORAGE) ' Allows an application to read from external storage.
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE) ' Allows an application to write to external storage.

SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.

Is it possible to write to a directory that is not a subfolder or the main program with sdk 26?
If so, what am I doing wrong?
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

GaryK4

Member
Licensed User
Longtime User
That may be what I am missing?
All I have is what you see in my manifest. I also log the GetAllSafeDirsExternal which only shows a subfolder of my program.

What do I need to add in my code to allow WRITE_EXTERNAL_STORAGE?
 
Upvote 0

GaryK4

Member
Licensed User
Longtime User
OK, I needed to add rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
The test program now works.

Thanks
 
Upvote 0
Top