How to find USB storage path programmatically? - android

I connected USB storage to my phone and I used
getExternalFilesDirs("");
to find all directories including sdcard and USB.
The path of sdcard comes out correctly, but USB path does not come out by the function.
Is there anyway to find relative path of USB instead of absolute path?
I've been stuck at this problem for few weeks, but got nothing.

Due to Android permissions you may not be able to do this, but here's the recommendation anyways. Try to read the contents of /proc/mounts and grep "sda1". It'll show you the mount point of your USB drive.

Related

How to read/write external USB storage on Android?

I am currently making an app that needs to be able to read from and write to a USB flash drive connected via a USB OTG adapter. Is there an easy way to access this storage via standard Java.io.File APIs? This app is only going to be run on a rooted Motorola Xoom running Android 4.2.2. Any suggestions would be appreciated.
USB Drives get mounted to your device just like an SDCard does essentially*.
The mount path usually resides at:
/storage/usb0/
I have not used this on many devices other then my Droid running CyanogenMod, your device may very. You can smiply use a file manager to explore this path. The directories will still exist even if there is no mount path, so you will be able to determine the path.

SD card contents in Android

My app writes a text file onto the phone's external storage. I know it works fine because I can find the file via a file manager. What I'm stumped by is this : I can see that the file has been created on the SD Card via the file manager on my phone. When I enable USB storage and connect it to my computer, I don't see the text file.
The path was : "mnt/sdcard/test.txt"
I can see it on my phone. When I mount the sd-card to my computer, I don't see it.
Why is this?
The user permissions have been set correctly. Otherwise the file will not be seen even on the phone.
If you agree to connect the USB storage then the SD card is unmounted and it's not visible to Android and only as USB storage device to the attached USB port.
If you are a developer and you want to investigate files on your device you should connect your device and use adb like that
adb shell ls /mnt/sdcard
There is nothing wrong, you are only missing what Android really does and how you are supposed to connect your terminal to the device.
Insert the following line of code to output the file to the SD card:
FileOutputStream f = new FileOutputStream(file);
Finally step 7:
In the location or Methode where you are saving the txt file within the SD card
Save the file, then compile it and test the application using the Android emulator software or the device.
This can works!!! ;-)

Need help about android mounting Sdcard

Im working on "mount ntfs sdcard"
That is problem:
- If i mount sdcard to another folder than /mtn/sdcard then my sdcard working find
- If i mount it to /mnt/sdcard then android not except it : " The SDcard is not currently mounted"
In adb shell i type mount command and see that my SDcard is mounted to /mnt/sdcard
But infact SDcard folder cannot accessable.
I think android doesnt except mount ntfs sdcard on /mnt/sdcard because it programed to mount vfat sdcard on /mnt/sdcard.
Now the question: where i can find mounting code or mounting procedure of android when we insert SDcard? i want to modify it to accept ntfs sdcard.
P/S: im on GB 2.3.6
This is a very specific question, I doubt you will get an answer here. You might want to try to locate it yourself from the source code which could be found here:
https://sites.google.com/a/android.com/opensource/download
I did some googling and found this:
http://cateee.net/lkddb/web-lkddb/NTFS_FS.html, you might need to modify it.
On Android, the mounting of the sdcard is managed by the vold daemon.
If you want a stable system, you likely need to either get vold to manage your custom mount, remove vold from the system and do it's entire job yourself, or somehow get it and your custom solution to stay out of each other's way.
Lots of custom ROMs have used vold in different ways - to partition an sdcard and add a unix-style filesystem for storing apps, to put an entire alternate android installation on an sdcard or tablet internal storage area, etc. You might get some ideas by looking at those, reading their development discussion history, etc.

Find SD card volume label on Android

Is it possible to find out volume label of SD card inserted into Android device?
I understand that Android is designed to have just one "external storage" (as returned by Environment.getExternalStorageDirectory()), but there are quite a few devices in the wild that have internal flash as "external storage" and an SD card mounted under that or even wilder combinations (see this other question). It is possible to enumerate these additional devices by reading /proc/mounts, but we need something to identify them to the user. Is there any chance to get to their volume labels?
I checked that Linux vfat driver ignores the volume label dentry altogether and that blkid from util-linux reads the vfat itself. I also checked that, at least on device I have, the block device of the SD card has mode 660 and owner root.root, so I can't do that. So basically it boils down to whether there is any utility that could read it available.
I have found a solution.
The easiest solution is to build busybox and use it like this:
busybox blkid
Complicated solution is to find blkid for Android and find what you need in its source code (blkid_dev_devname function).
i don't know how it works exactly in android, but in linux i have kernel message about mounting sd-card, where volume name specified. You can try dmesg and cat /sys/devices/mmc... (or somethong like that)
Try to parse output of blkid command. It works for me, but I'm not sure if it is a firmware depended feature or not. I got permission denied with this command on AVD.
I don't know if this can help you: if you use the DDMS you can see the folders of the system. In my case, I found the sd card in: /mnt/media_rw.
You can get more information here and here
I hope it helps.

Android - inconsistent ringtone behavior

I am trying to add ringtones to the media/ringtones folder from my application. If the phone is connected via USB to a computer or mounted on my Mac, the ringtones do not show up in the SD Card, nor in the Ringtone settings.
But if I run the application with the USB unplugged, the ringtones appear ok. This is not a problem with Ringdroid which does the same thing.
Can someone please tell me what could be wrong.
Did you check the setting for usb mass storage? It should be off if you want to access the content of the sd card from the phone.
If you mount the SDCard on your Mac, your Phone canĀ“t acces it.
So, if you want to use the SDCard on your phone, it has to be mounted there (and nowhere else).

Categories

Resources