£50 for the first working solution. SDK30 Android/data read/write

Magma

Expert
Licensed User
Longtime User
aidymp... search how can be ... if it can be in java... not sure...

but "really" why not making a wish...

Anytime get into there - i feel lucky ! - and have in mind that this you are asking - need many users too.. so more users... fast tip !
 

Xfood

Expert
Licensed User
this is the code I use, and for now it seems to work for me

B4X:
For Each permission As String In Array(rp.PERMISSION_READ_EXTERNAL_STORAGE,rp.PERMISSION_CAMERA,rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
            rp.CheckAndRequest(permission)
            Wait For Activity_PermissionResult (permission As String, Result As Boolean)
            If Result = False Then
                ToastMessageShow("No permission!", True)
                Activity.Finish
                Return
            End If
        Next


I add this to the manifest
B4X:
'Manifest'

AddPermission("android.permission.READ_EXTERNAL_STORAGE")
AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")
'
SetApplicationAttribute(android:requestLegacyExternalStorage, true)
 

aidymp

Well-Known Member
Licensed User
Longtime User
on Android 11??
 

agraham

Expert
Licensed User
Longtime User
Sorry your being very cryptic! LOL
Cryptic? - How? I'm being as precise as I can be

SetApplicationAttribute(android:requestLegacyExternalStorage, true)
That's a temporary workaround that will only work on SDK 29 targets. You should have read it here

There is no need to manually add the "AddPermission" lines to the manifest. B4A should add them and you automatically get read permission if you ask for write permission.
 

Xfood

Expert
Licensed User
this is my manifest, in fact if you don't put sdk 30 you can't publish on playstore
I Public On Playstore



 

aidymp

Well-Known Member
Licensed User
Longtime User
Cryptic? - How? I'm being as precise as I can be

Sorry I have twin boys with Autism, They make me lose concentration quite easily.. I basically read your "Barking at the moon" and then your reply that said it can be done in B4A, I was confused... no offence was implied.

Thanks

Adrian
 

aidymp

Well-Known Member
Licensed User
Longtime User

aidymp

Well-Known Member
Licensed User
Longtime User
Nope> As I have said before ad nauseam. You won't be able to without using the Storage Access Framework hack.

yes i am aware, but the hack has gone clean over my adhd head!

hence my small offer, if someone could provide small, clear steps.

or a big massive sign that would be great...

what i got from your comments was the secret is in the class??

but the class is mostly java and in my (basic coders) eyes contains nothing relating to a file path?

i noted that the permission would attept to access the Android/data folder and the user would pick said folder and access would be granted but that is clearly way above my knowledge.

am i close??
 

agraham

Expert
Licensed User
Longtime User
OK, I wasn't going to bother but you wore me down. Try this project. It has a modified External Storage class module that opens Android/data as the pre-selected folder so the user should just press "Use this folder". The user can navigate away but will not be able to navigate back so you need to check he has selected Android/data by looking at ExernalStorage.Root.Name which should look like

content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fdata

You need to use the other ExternalStorage methods to access files and folders, the usual file methods will not work.
 

Attachments

  • ExternalStorage30.zip
    12.5 KB · Views: 495
Last edited:

agraham

Expert
Licensed User
Longtime User
Slight bug in crude demo above. It doesn't appear to persist the permission because I commented out a line while testing. In Main.btnPickFolder_Click un-comment the commented call

Storage.SelectDir(chkUsePreviouslySelected.Checked)

and delete the following line passing False.
 
Last edited:

aidymp

Well-Known Member
Licensed User
Longtime User

Hi, I will look when the kids are in bed, so far in windows its still showing an empty folder, but it does look promising! I will keep you updated.
 

agraham

Expert
Licensed User
Longtime User
It works on all three Android 11 and 12 devices I tried so far.

Starting the demo for the first time the screen will be an empty black File Picker with a white ImageView at the lower right. Pressing "Pick folder" should show an Android system screen with the contents of the data folder and a "Use this folder" button at the bottom. Press it and allow access in the dialog and it will return to the blank screen and after a delay (Storage Access Framework is a bit slow) show you all the folders in /data. You can now navigate those folders and if you select a jpg file it will display in the ImageView. Study the source code to see how it accesses files.

If you press "Pick folder" again with the CheckBox checked regardless of what is displaying it will return to the /data folder. Unchecking the Checkbox will ask again for access as it will not then use the persisted permission.
 

aidymp

Well-Known Member
Licensed User
Longtime User
Very promising, Im going to do the unthinkable, and update my Nvidia Shield to Android 11! As my tablet is currently with samsung, and my phone is locked to Android 10, And Windows subsystem for Android is being silly! But as soon as I can confirm it works I will pay as promised.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…