Android Question Permissions not sufficient , still can't access external files correctly.

Adamdam

Active Member
Licensed User
Longtime User
Dear all,
Greetings,
I try to access external files from my app (i.e. File.DirRootExternal) but access get error.
I used this code to grant Permissions :



</

Sub File_Permission
Dim PermissionsGoodFlag As Boolean = True
If PermissionsGoodFlag Then
rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, YaeOrNay As Boolean)
If YaeOrNay = False Then
PermissionsGoodFlag = False
End If
End If

PermissionsGoodFlag = True

If PermissionsGoodFlag Then
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, YaeOrNay As Boolean)
If YaeOrNay = False Then
PermissionsGoodFlag = False
End If
End If
End Sub
>

and even this is the content of manifest file:

</
AddManifestText(
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="31"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
AddPermission("android.permission.READ_EXTERNAL_STORAGE")
AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")
'End of default text.
>

What I must add to get a full Permissions to access external files

Best regards
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Many thanks for your attention.
Kindly how can I use ContentResolver instead of File.DirRootExternal are you have any example, please?
for very simple following code :

B4X:
            If File.Exists(File.DirRootExternal * "\Abc", "As_16.vx") = False Then
                File.Copy(File.DirAssets, "As_16.vx", File.DirRootExternal * "\Abc", "As_16.vx")
            End If
           
            SQL2.Initialize(File.DirRootExternal * "\Abc", "As_16.vx", False)
            Curser2 = SQL2.ExecQuery("SELECT * FROM Tabel1 order by id" )
           
            For i = 1 To Curser2.RowCount
                .
                .
                .
Thanks on advance for you.
I don't have an example because I haven't implemented it in B4X (only in Kotlin). I'd suggest you start here -> https://www.b4x.com/android/forum/threads/externalstorage-access-sd-cards-and-usb-sticks.90238/

- Colin.
 
Upvote 0

zed

Active Member
Licensed User
There are enough articles devoted to permissions and access to files on the forum, so as not to include examples yet.
It would just be duplicates.
Take the time to search the forum for information.
Everything you need to know about it is already here
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Dear all,
Greetings,
I try to access external files from my app (i.e. File.DirRootExternal) but access get error.
I used this code to grant Permissions :



</

Sub File_Permission
Dim PermissionsGoodFlag As Boolean = True
If PermissionsGoodFlag Then
rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, YaeOrNay As Boolean)
If YaeOrNay = False Then
PermissionsGoodFlag = False
End If
End If

PermissionsGoodFlag = True

If PermissionsGoodFlag Then
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, YaeOrNay As Boolean)
If YaeOrNay = False Then
PermissionsGoodFlag = False
End If
End If
End Sub
>

and even this is the content of manifest file:

</
AddManifestText(
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="31"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
AddPermission("android.permission.READ_EXTERNAL_STORAGE")
AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")
'End of default text.
>

What I must add to get a full Permissions to access external files

Best regards
use contentresolver
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Thanks Mr. Alex
Kindly, are you have the way? or example ? or link in this community for this solution, I spent lot time to search but can't find it.
Thanks on advance.
I already gave you the link to where you can get more information.

https://www.b4x.com/android/forum/threads/externalstorage-access-sd-cards-and-usb-sticks.90238/

The second point says:
This class can also be used to access the secondary storage (File.DirRootExternal). This becomes relevant with newer versions of Android that restrict direct access.

You need to read through that thread & work it out for yourself & look at the example included with the first post.

- Colin.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Thanks Mr. Alex
Kindly, are you have the way? or example ? or link in this community for this solution, I spent lot time to search but can't find it.
Thanks on advance.
here it is
 

Attachments

  • DocumentPicker.zip
    13.8 KB · Views: 122
Upvote 0
Top