Android中有关于获取外挂设备的路径以及基本信息

/** * 获取所有存储卡挂载路径 * @return */ /* public static List getMountPathList() { List pathList = new ArrayList(); final String cmd = "cat /proc/mounts"; Runtime run = Runtime.getRuntime();//取得当前JVM的运行时环境 try { Process p = run.exec(cmd);//执行命令 BufferedInputStream inputStream = new BufferedInputStream(p.getInputStream()); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = bufferedReader.readLine()) != null) { // 获得命令执行后在控制台的输出信息 //Log.d( "MainActivity", line ); //输出信息内容: /data/media /storage/emulated/0 sdcardfs rw,nosuid,nodev,relatime,uid=1023,gid=1023 0 0 String[] temp = TextUtils.split(line," "); //分析内容可看出第二个空格后面是路径 String result = temp[1]; File file = new File( result ); //类型为目录、可读、可写,就算是一条挂载路径 if (file.isDirectory() && file.canRead() && file.canWrite()) { //if ( file.isDirectory() && file.canRead() ) { Log.d( "MainActivity", "add -->" + file.getAbsolutePath()); pathList.add(result); } // 检查命令是否执行失败 if (p.waitFor() != 0 && p.exitValue() == 1) { // p.exitValue()==0表示正常结束,1:非正常结束 Log.e("MainActivity", "命令执行失败!"); } } bufferedReader.close(); inputStream.close(); } catch (Exception e) { Log.e( "MainActivity", e.toString() ); //命令执行异常,就添加默认的路径 pathList.add(Environment.getExternalStorageDirectory().getAbsolutePath()); } return pathList; } */ /* public String getUsbStorageName() { String name = ""; /* try { //获得外接USB输入设备的信息 Process p = Runtime.getRuntime().exec("cat /proc/bus/input/devices"); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while( (line = in.readLine()) != null ){ String deviceInfo = line.trim(); Log.d("MainActivity", deviceInfo); } } catch (Exception e) { e.printStackTrace(); } */ /* //获得各盘符路径 DeviceMountInfo dev = DeviceMountInfo.getInstance(); DeviceMountInfo.DevInfo info; info = dev.getInternalInfo(); Log.d("MainActivity", info.getLabel() + ":" + info.getMount_point()); Environment.getExternalStorageDirectory() 这两个要是不一样咋办 info = dev.getExternalInfo(); Log.d("MainActivity", info.getLabel() + ":" + info.getMount_point()); info = dev.getUSBInfo(); Log.d("MainActivity", info.getLabel() + ":" + info.getMount_point()); *//* UsbManager manager = (UsbManager)getSystemService(Context.USB_SERVICE); HashMap deviceList = manager.getDeviceList(); if (deviceList.size() == 0) { return name; } Iterator deviceIterator = deviceList.values().iterator(); UsbDevice device; while( deviceIterator.hasNext() ) { device = deviceIterator.next(); Log.d(TAG, "Name: " + device.getDeviceName()+"\n" + "VID:" + device.getVendorId() + " PID:" + device.getProductId() + " PN:" + device.getProductName() + " DID:" + device.getDeviceId() + " MN:" + device.getManufacturerName() + " SN:" + device.getSerialNumber() ); //data.add("Name: " + device.getDeviceName()+"\n" // + "VID: " + device.getVendorId() // + "PID: " + device.getProductId()); } return name; } */
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值