本方法是检测文件/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();
}
}
文件/proc/partitions内容大概为如下内容:
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 32 2048 mmcblk0boot1
179 16 2048 mmcblk0boot0
8 0 15360000 sda
8 1 15355968 sda1