equivalent for getExternalStoragePublicDirectory

wizardly

New Member
Licensed User
Longtime User
I need to save a text file to one of the public directories on the external storage. This file will be viewed by the user via a file manager or on the pc, meaning not in my app.

The delevoper.andriod.com site states: "In API Level 8 or greater, use getExternalStoragePublicDirectory(), passing it the type of public directory you want, such as DIRECTORY_MUSIC, DIRECTORY_PICTURES, DIRECTORY_RINGTONES, or others. This method will create the appropriate directory if necessary."

Can anyone tell me how to find and/or reference the public Download folder using B4A?
 

wizardly

New Member
Licensed User
Longtime User
OK, that's great!
Except when I look in those folders (via pc or file explorer) I can't see any text files...I know they are there because I can open and read the contents of the files in my app. When I check the path it is giving me /storage/sdcard0 which I think is the correct place for public files.
I am using file.writestring and file.readstring
Bottom line - how can I create and save text files that the user can access from his computer or file explorer, not just my own app?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The native getExternalStoragePublicDirectory method returns the folders under File.DirRootExternal.

On some Android devices there are more than one external storage. In most devices both should be accessible when the device is USB connected. There is no standard API in Android to return the additional external storage.
 
Upvote 0

wizardly

New Member
Licensed User
Longtime User
Yes your information on the directory was correct and I am able to save files and open files with the device. My problem is that I can't see any of my text files in Windows Explorer. I can see all the public folders and other files. The only thing missing are my app text files. Could this be a security setting, or something else? I really need a solution for getting text files my app creates into a folder the user can access via the pc! I realize this may not be related to B4A specifically.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
You can use File.Combine(File.DirRootExternal, "xxx") where xxx is Pictures / Music / Ringtones (these are the constants values).
I am unclear on this. I need to find out the NAME of the directory, specifically I am looking for DIRECTORY_DOWNLOADS getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS) will return the name of this directory, and create it if it doesn't exist. How does FIle.Combine accomplish this? I know on my Samsung Note 2 the directory is called Download, NOT DOWNLOADS, so the spelling is different and again on my Note all directories are Capitalized, not ALLCAPS as the constants are and as I understand it the Android file system is case sensitive? So MUSIC would not work if the device dir is Music.
 
Upvote 0
Top