Android Question External SD Card on Android 5+

chrjak

Active Member
Licensed User
Longtime User
Hey Community

I managed all permissions and i have the permission for the external sd. nevertheless i get a Permission denied error when i try to write on my sd card

i saw many apps that somehow call the system file manager(?) and say you have to select the sd and click ok. after that they can access my sd card
How can i call this?

i have the samsung galaxy s7 edge

I found an example which uses that feature:
AirDroid
https://www.dropbox.com/s/8ja3j5n183wjbjn/Screenshot 2017-01-21 20.33.23.png?dl=0
 
Last edited:

chrjak

Active Member
Licensed User
Longtime User
On my research i found very interesting sites:
https://metactrl.com/docs/sdcard-on-lollipop/

and the most useful:
http://www.androidcentral.com/lollipop-brings-changes-way-your-sd-card-works-kind-youll
in Lollipop we added the new ACTION_OPEN_DOCUMENT_TREE intent. Apps can launch this intent to pick and return a directory from any supported DocumentProvider, including any of the shared storage supported by the device. Apps can then create, update, and delete files and directories anywhere under the picked tree without any additional user interaction.
 
Upvote 0

chrjak

Active Member
Licensed User
Longtime User
I know but I want to access the full sd card. e.g. a custom path on the sd card which the user sets by himself

this intent solution would solve it all. could somebody watch over it and say how to make it in b4a please?
 
Upvote 0

chrjak

Active Member
Licensed User
Longtime User
I think many members have the same question

with RP i only get the app folder on the sd card but i want to access the whole sd card. How it works is above but i don't know how to put this intent into b4a especially because it returns an uri if i am not wrong.

Additionally this system file manager may be useful to many members so that they dont have to code their own one

Please help me
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
but i want to access the whole sd card
It is not possible in newer versions of Android (Starting from Android 5 i think). Only one path is available to your app.

You have to live with that i guess.
 
Upvote 0

chrjak

Active Member
Licensed User
Longtime User
It is not possible in newer versions of Android (Starting from Android 5 i think). Only one path is available to your app.

You have to live with that i guess.
it is. Only on android kitkat (4.4) is no way to access it without root. the details are above. google added the opportunity to call the system file manager and the app gets access to the selected path

in Lollipop we added the new ACTION_OPEN_DOCUMENT_TREE intent. Apps can launch this intent to pick and return a directory from any supported DocumentProvider, including any of the shared storage supported by the device. Apps can then create, update, and delete files and directories anywhere under the picked tree without any additional user interaction.

Apps do this, google says this
so it looks like it is possible. I linked the articles above and below again

As soon as i have the solution for b4a i will write a thread about sd usage to help other members
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

chrjak

Active Member
Licensed User
Longtime User
Ok I tried my best and thats the result: It works on my device and you get a thing looking like this out of the DocumentTree:
content://com.android.externalstorage.documents/tree/9C33-6BBD%3Afolder1%2Ffolder2
In Java there is a function for this (DocumentFile pickedDir = DocumentFile.fromTreeUri(this, treeUri);) but as I can only handle this string i fixed the information in it and added storage paths etc.
(This is only tested on Samsung Galaxy S4 and S7 Edge - Other Phones might have a different storage path system. If you experience problems with my project please let me know)

An Example Project is attached
This is just a quick solution {TreeString} fix. Maybe there is a better way
 

Attachments

  • SdCardV1.zip
    7.5 KB · Views: 959
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Hi chrjak,
This works well on my S7.
Is there a way to get the folder name of the DCIM/Camera folder that is stored on the External SD card? I need to read and write from/to it...
I would like to get to the photos (with an app) that are stored externally.
Thanks,
Rusty
 
Upvote 0
Top