Android Question Runtime permissions - external storage

RJB

Active Member
Licensed User
Longtime User
(the search facility doesn't seem to be working today, so sorry if this is a duplicate)
The documentation for run time permissions quote the following to be added to the manifest editor:
B4X:
AddManifestText(<uses-permission 
android:name="android.permission.WRITE_EXTERNAL_STORAGE" 
android:maxSdkVersion="18" /> 
)
Should it actually say ="22"?
I spent a while trying to get a device with Android 4.4.2 working until I changed this.
 

Peter Simpson

Expert
Licensed User
Longtime User
You can just use the following in the manifest editor.
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
<supports-screens android:largeScreens="true" 
    android:normalScreens="true" 
    android:smallScreens="true" 
    android:anyDensity="true" />)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
It will work just fine, and don't forget to add the RTP code into your activity...
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
You can just use the following in the manifest editor.
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true" />)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
It will work just fine, and don't forget to add the RTP code into your activity...
Well that seems much simpler - thanks!
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It should be 18. This is will work if you use RuntimePermissions.GetSafeDirExternal to get the folder path.

Google documentation:
For example, beginning with Android 4.4 (API level 19), it's no longer necessary for your app to request the WRITE_EXTERNAL_STORAGE permission when your app wants to write to its own application-specific directories on external storage (the directories provided by getExternalFilesDir()). However, the permission is required for API level 18 and lower. So you can declare that this permission is needed only up to API level 18 with a declaration such as this:

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
This way, beginning with API level 19, the system will no longer grant your app the WRITE_EXTERNAL_STORAGE permission.

This attribute was added in API level 19.
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
It should be 18. This is will work if you use RuntimePermissions.GetSafeDirExternal to get the folder path.

Google documentation:
For example, beginning with Android 4.4 (API level 19), it's no longer necessary for your app to request the WRITE_EXTERNAL_STORAGE permission when your app wants to write to its own application-specific directories on external storage (the directories provided by getExternalFilesDir()). However, the permission is required for API level 18 and lower. So you can declare that this permission is needed only up to API level 18 with a declaration such as this:

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
This way, beginning with API level 19, the system will no longer grant your app the WRITE_EXTERNAL_STORAGE permission.

This attribute was added in API level 19.
All I know is that I couldn't write to the directory returned by rp.GetSafeDirDefaultExternal("") on an Android 4.4.2 (API 19?) device (i.e I couldn't create any directories) until I increased the number above 18. Then it all started to work. The solution suggested by Peter Simpson also seems to work.
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
So I should call re.Get... multiple times, once for each directory?
Will I then be able to use makedir for subdirectories? And be able to create files within them?
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
Thanks.

So for 'Dir' and 'Dir/Subdir'. I would do rp.GetSafeDirDefaultExternal("Dir") Then rp.GetSafeDirDefaultExternal("Dir/SubDir")?
Just tried and it seems to work:
B4X:
For i = 0 To 9
    rp.GetSafeDirDefaultExternal("Dir" & i)
    rp.GetSafeDirDefaultExternal("Dir" & i & "/SubDir")
Next
 
Upvote 0
Top