Android detects if one of the USB stick methods is inserted

Source: Internet
Author: User

This method is to detect file/proc/partitions.

Import java.io.*;


File Usbfile = new file ("/proc/partitions");
if (usbfile.exists ()) {
try {
FileReader file= New FileReader ("/proc/partitions");
BufferedReader br=new BufferedReader (file);
String strline= "";
while ((Strline=br.readline ())!=null)
{
if (Strline.indexof ("SD") >0)
{
LOG.D ("Debug_xyp", "Udisk insert---------->" +
"[" +thread.currentthread (). Getstacktrace () [2].getfilename () + "," +thread.currentthread (). Getstacktrace () [2]. Getlinenumber () + "]");

Break
}
}
Br.close ();
File.close ();
} catch (Exception e) {
E.printstacktrace ();
}
}

The file/proc/partitions content is probably as follows:

Major Minor #blocks name

179 0 3866624 Mmcblk0
179 1 655352 Mmcblk0p1
179 2 393208 MMCBLK0P2
179 3 524280 Mmcblk0p3
179 4 1 MMCBLK0P4
179 5 16376 MMCBLK0P5
179 6 16376 MMCBLK0P6
179 2048 MMCBLK0BOOT1
179 2048 Mmcblk0boot0
8 0 15360000 SDA
8 1 15355968 sda1

Android detects if one of the USB stick methods is inserted

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.