Android Question Create a folder visible to a PC

Roger C

Active Member
Licensed User
Longtime User
Hi all,

I've been searching and trying a lot of examples in this forum but I can't understand nor get it to work as I want.

I want to create a folder in the device that is visible when you on the PC's explorer navigate to the phone and open InternalStorage.
I've tried most of things but they all end up in emulated...something and it's not visible from the PC.

What code do I need to create a folder and what is the path for saving something into that folder?
 

Attachments

  • InternalStorage.jpg
    InternalStorage.jpg
    67.6 KB · Views: 316

Mahares

Expert
Licensed User
Longtime User
I've been searching and trying a lot of examples in this forum but I can't understand nor get it to work as I want.
In manifest I used a target of 22 to avoid permission. If you use a target of 23 or higher you have to deal with runtime permissions for external. This is a complete example:
B4X:
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="22"/>
B4X:
Sub Globals
    Private MyFolder As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
    File.MakeDir(File.DirRootExternal,"roger")  'create a folder called roger in root
    MyFolder=File.DirRootExternal & "/roger"   'assign a variable to the folder
    File.WriteString(MyFolder,"myfile.txt","There are a lot of very helpful dudes in this forum")  'save a string to the folder
End Sub
To see the folder and the file that is created in it on your PC like in the image you posted, you may have to unplug and re-plug the USB cable to refresh. I hope I am not being too simplistic or naive if you already tried something like what I described above.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I want to create a folder in the device that is visible when you on the PC's explorer navigate to the phone and open InternalStorage.

Excuse me if I am telling you something that you already know, but are you clear about the difference between what most people think of as a 'phone's "internal storage" (that is, the 'phone's memory) and what Android calls "Internal storage" (such as is used with File.DirInternal)?

Files and directories written using File.DirInternal etc are internal to the app; they are not accessible to other apps and certainly not to an attached PC. But if you use File.DirExternal then the files are written in the public area of the 'phone memory. Some people think that File.DirExternal refers to something like an SD card, but that is not the case. If you write folders using File.DirExternal then they will be accessible to a PC.

There is another complication that can happen. Sometimes when you hook up to a PC the devices create an MTP connection (Media Transfer Protocol) and this prevents you seeing the 'phone memory at all. I think that this depends on the driver in the PC. If this is the problem then you have to find a way to connect your 'phone for file transfer. The way to do this varies from 'phone to 'phone and can be a real nuisance.

Again, I am sorry if you already understand this, but it confused me for a while.
 
Upvote 0
Top