Android Question WRITE_EXTERNAL_STORAGE error

hanyelmehy

Active Member
Licensed User
Longtime User
i use this in manifest
B4X:
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
B4X:
RP.Check(RP.PERMISSION_WRITE_EXTERNAL_STORAGE)
return true
and when i try to copy file to EXTERNAL_STORAGE i get
B4X:
(ErrnoException) android.system.ErrnoException: open failed: EACCES (Permission denied)
test done with B4A 6.3 and android 6.0
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
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

hanyelmehy

Active Member
Licensed User
Longtime User
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

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you want to allow the user to choose File.DirRootExternal then you should remove this section from the manifest editor:
B4X:
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

hanyelmehy

Active Member
Licensed User
Longtime User
If you want to allow the user to choose File.DirRootExternal then you should remove this section from the manifest editor:
B4X:
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
B4X:
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

hanyelmehy

Active Member
Licensed User
Longtime User
also what is the behavior for
B4X:
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
B4X:
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top