Android开发中如何获取外置TF卡的路径
来源:互联网 发布:皓月乒乓 淘宝店铺 编辑:程序博客网 时间:2024/04/27 21:15
Android获取外部SDcard的官方调用是
Environment.getExternalStorageDirectory()
但是根据不同机型,是有不同的结果的。
如果手机支持TF卡扩展,并且本身没有大容量存储,比如说HTC老款手机 G3之类的,那么获取到的是TF卡的路径。这是对的。
如果手机本身有大容量存储,不论手机是否支持TF卡扩展,比如现在HTC系列高端手机One X,或者920 butterfly系列,那么获取到的是大容量存储的路径。
也就是说,如果手机本身具有大容量存储,又支持TF卡扩展,通过这条命令是无法获取到TF卡信息的。
我查了半天,没有看到明确获取到扩展存储的API方法,如果有,请你告诉我,谢谢。(cst05001 at 狗妹儿)
那么怎么解决这个问题呢。网上有人说用/sdcard/extSdCard路径之类,这是不对的。因为不同的ROM,对外部存储的挂载点是会不一样的。比如三星国行,挂载点是/Storage/extSdCard 。
这是我从系统角度想到的解决办法,不用越狱,不用权限。大家可以参考:
try {Runtime runtime = Runtime.getRuntime();Process proc = runtime.exec("mount");InputStream is = proc.getInputStream();InputStreamReader isr = new InputStreamReader(is);String line;String mount = new String();BufferedReader br = new BufferedReader(isr);while ((line = br.readLine()) != null) {if (line.contains("secure")) continue;if (line.contains("asec")) continue;if (line.contains("fat")) {String columns[] = line.split(" ");if (columns != null && columns.length > 1) {mount = mount.concat("*" + columns[1] + "\n");}} else if (line.contains("fuse")) {String columns[] = line.split(" ");if (columns != null && columns.length > 1) {mount = mount.concat(columns[1] + "\n");}}}txtView.setText(mount);} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}
2 2
- Android开发中如何获取外置TF卡的路径
- Android开发中如何获取外置TF卡的路径
- 如何获取外置的SD卡路径
- Android手机外置SD卡(TF卡)的获取方法
- android 获取外置SD卡的路径
- android获取外置SD卡的路径
- Android 内部存储(外置SD卡)和扩展存储卡(TF卡)路径的获取
- 获取SD卡 tf卡 内置外置存储卡路径名称 路径的方式
- Android获取机身存储、内置SD卡与外置TF卡路径
- Android中获取内置SD卡和外置SD卡路径的方法
- android 获取外置SD卡的路径(非挫版)
- android 获取外置SD卡的路径(非挫版)
- 获取android系统外置存储卡路径的方法
- android 获取外置SD卡的路径(非挫版)
- Android获取系统外置存储卡路径的方法
- Android获取系统外置存储卡路径的方法
- Android获取系统外置存储卡路径的方法
- Android获取内置和外置sd卡路径的方法
- webview
- Linux 下网络性能优化方法简析
- 11G重建scott
- 分享一款超好用的手机软件——云脉文档识别V3.0.140117
- android/源码编译
- Android开发中如何获取外置TF卡的路径
- UVa 264 - Count on Cantor
- 您必须拥有这台计算机上的终端服务器用户访问权限的解决方案
- codeforces6A--Triangle
- linux错误码
- NSOperationQueue与GCD的使用原则和场景
- makefile的语法及写法
- 输出EXCEL报表时如何将科学计数法字段改为文本
- 位运算.