Android Question WRITE_EXTERNAL_STORAGE error

hanyelmehy

Well-Known Member
Licensed User
Longtime User
i use this in manifest
Code: Copy
AddManifestText(
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23"/>
AddManifestText(
<uses-permission
  android:name="android.permission.WRITE_EXTERNAL_STORAGE"
  android:maxSdkVersion="18" />
)
AddManifestText(
<uses-permission
  android:name="android.permission.READ_EXTERNAL_STORAGE"
  android:maxSdkVersion="18" />
)
When check for
Code: Copy
RP.Check(RP.PERMISSION_WRITE_EXTERNAL_STORAGE)
return true
and when i try to copy file to EXTERNAL_STORAGE i get
Code: Copy
(ErrnoException) android.system.ErrnoException: open failed: EACCES (Permission denied)
test done with B4A 6.3 and android 6.0
 
1. It is almost always a mistake to call RP.Check. You should use RP.CheckAndRequest and continue the program flow from the PermissionResult event.
2. Your code is wrong. You have confused two different things. If you set the maxSdkVersion to the permission then you need to use RuntimePermission.GetSafeDirDefaultExternal.
 
Upvote 0
1. It is almost always a mistake to call RP.Check. You should use RP.CheckAndRequest and continue the program flow from the PermissionResult event.
2. Your code is wrong. You have confused two different things. If you set the maxSdkVersion to the permission then you need to use RuntimePermission.GetSafeDirDefaultExternal.
Thank you for your answer
i get no 1
i still have confused about no 2 :
in my app ,after download a file i save it to (File.DirInternalCache) ,and i asked user to save it in any other place if he want ,what is your recommendation to do that ,because i have above problem if user select external storage path
 
Upvote 0
If you want to allow the user to choose File.DirRootExternal then you should remove this section from the manifest editor:
Code: Copy
AddManifestText(
<uses-permission
 android:name="android.permission.WRITE_EXTERNAL_STORAGE"
 android:maxSdkVersion="18" />
)
AddManifestText(
<uses-permission
 android:name="android.permission.READ_EXTERNAL_STORAGE"
 android:maxSdkVersion="18" />
)
 
Upvote 0
If you want to allow the user to choose File.DirRootExternal then you should remove this section from the manifest editor:
Code: Copy
AddManifestText(
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)
AddManifestText(
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)
so i well use only
Code: Copy
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)

because when i use this and test on android 6 i get java.io.FileNotFoundException: /mnt/m_external_sd/file name: open failed: EACCES (Permission denied)
 
Upvote 0
also what is the behavior for
Code: Copy
RP.CheckAndRequest(RP.PERMISSION_WRITE_EXTERNAL_STORAGE)
RP.CheckAndRequest(RP.PERMISSION_READ_EXTERNAL_STORAGE)
when app run on android 4.0 when targetSdkVersion is set to 23 or above.
and use
Code: Copy
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
 
Upvote 0
Upvote 0
Back
Top