900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > android u盘检测工具 android 检测是否插入U盘方法之一

android u盘检测工具 android 检测是否插入U盘方法之一

时间:2024-06-30 20:20:25

相关推荐

android u盘检测工具 android 检测是否插入U盘方法之一

本方法是检测文件/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 3866624mmcblk0

179 1 655352mmcblk0p1

179 2 393208mmcblk0p2

179 3 524280mmcblk0p3

179 4 1mmcblk0p4

179 5 16376 mmcblk0p5

179 6 16376 mmcblk0p6

179 32 2048 mmcblk0boot1

179 16 2048 mmcblk0boot0

8 0 15360000 sda

8 1 15355968 sda1

原文:/hei-da-mi/p/4494026.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。