Android以编程方式获取SD卡的ID
作者:互联网
有什么方法可以通过编程方式获取Android设备中当前SD卡的某些特定标识符/序列号?
解决方法:
是的,请尝试以下操作:
public String getSDCARDiD()
{
String sd_cid = null;
try {
File file = new File("/sys/block/mmcblk1");
String memBlk;
if (file.exists() && file.isDirectory()) {
memBlk = "mmcblk1";
} else {
//System.out.println("not a directory");
memBlk = "mmcblk0";
}
Process cmd = Runtime.getRuntime().exec("cat /sys/block/"+memBlk+"/device/cid");
BufferedReader br = new BufferedReader(new InputStreamReader(cmd.getInputStream()));
sd_cid = br.readLine();
//System.out.println(sd_cid);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sd_cid;
}
标签:android,uniqueidentifier,android-sdcard 来源: https://codeday.me/bug/20191012/1901559.html