The method of recognizing and mounting a U disk by Android programming _android

Source: Internet
Author: User

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

# Create Mountpoints

Add a piece of

Mkdir/mnt/udisk 0076 System System

2. In

# Backwards Compat

Add a piece of

Symlink/mnt/udisk/udisk

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.