This paper illustrates the method of recognizing and mounting USB disk with Android programming. Share to everyone for your reference, specific as follows:
About U disk mount can first look at this article "Android2.3 to achieve SD card and U disk automatic Mount method", the author is a U disk directly mounted on the SD card. My machine is MTK6575 platform, support SDcard and SDCARD2, the test will be mounted to the U disk Sdcard2 can be realized under the U disk, but this is only a temporary solution, because at the same time to plug the Sdcard2 and USB in case there may be conflict, For example, two devices the same directory with the same file name can only identify one.
To implement a true USB stick mount, you need to modify several files:
I. Modification of VOLD.FSTAB
Add a dev_mount udisk/mnt/udisk auto/devices/platform/mt_usb/usb1
Ii. Modification of Init.rc
1. In
Add a piece of
Mkdir/mnt/udisk 0076 System System
2. In
Add a piece of
Third, modify Storage_list.xml, this document in frameworks/base/services/java/com/android/server/ Mountservice.java's Readstoragelist method is called to the.
private void Readstoragelist (resources) {
mvolumes.clear ();
Mvolumemap.clear ();
int id = com.android.internal.r.xml.storage_list;
Xmlresourceparser parser = resources.getxml (ID);
AttributeSet attrs = xml.asattributeset (parser);
The storage_list.xml is parsed here and the path to the external storage device (such as "Mnt/sdcard") is broadcast to the upper layer, and the upper layer receives the broadcast and scans the device according to the path.
...
}
The system is storage_list.xml in the Frameworks/base/core/res/res/xml directory with the following contents
<storagelist xmlns:android= "Http://schemas.android.com/apk/res/android" >
<!--removable is isn't set in Nosdcard product-->
<storage android:mountpoint= "/mnt/sdcard"
@string/ Storage_sd_card "
android:removable=" true "
android:primary=" true "/>
</StorageList>
The first time I put a piece in this file
<storage android:mountpoint= "/mnt/udisk"
android:storagedescription= "@string/storage_sd_card"
Android:removable= "true"
android:primary= "false"/>
After recompiling the test is invalid, because of the MTK platform code, so Storage_list.xml is likely to be MTK code coverage, so the source under the search Storage_list.xml, indeed in the following directory found.
./mediatek/custom/{project Name}/resource_overlay/generic/frameworks/base/core/res/res/xml/storage_list.xml
./mediatek/custom/{project Name}/resource_overlay/generic_emmc/frameworks/base/core/res/res/xml/storage_ List.xml
./mediatek/custom/{project Name}/resource_overlay/generic_nand/frameworks/base/core/res/res/xml/storage_ List.xml
For insurance purposes, I've added the following code to all three files.
<storage android:mountpoint= "/mnt/udisk"
android:storagedescription= "@string/storage_usb"
android: Removable= "true"
android:primary= "false"/>
After the new test can identify U disk, different platform to modify the way there are some differences, here the method is for reference only.
More interested readers of Android-related content can view this site: Android Development Primer and Advanced tutorial, Android resource Operation tips Summary, Android View view tips Summary and Android control usage summary
I hope this article will help you with the Android program.