获取SD卡地址 版本兼容

如有错误,欢迎各位大神指正。在此谢过!

问题:

平时工程中获取SD卡路径都是用Environment.getExternalStorageDirectory().getAbsolutePath();

返回的路径是:/storage/emulated/0

今天来了个新设备集智达高通处理器版,执行截屏报错。截屏代码如下:

String usbPath = Environment.getExternalStorageDirectory().getAbsolutePath();

String screencap="screencap -p "+StoragePathCommon.SDCARD_PATH+"/screen.png\n";

StringexecShellStr(screencap);

报错:

Error opening file: /storage/emulated/0/screen.png (No such file or directory)

其它硬件获取到的路径都是/storage/emulated/0执行没有问题。但是这个就是不行。

解决方案:

String usbPath = System.getenv("EXTERNAL_STORAGE")

String screencap="screencap -p "+StoragePathCommon.SDCARD_PATH+"/screen.png\n";

StringexecShellStr(screencap);

System.getenv("EXTERNAL_STORAGE")获取到的地址是:/storage/emulated/legacy

参考文章: http://moonlightbox.logdown.com/posts/2015/04/23/android-storage-emulated-legacy-vs-storage-emulated-0

http://blog.fidroid.com/post/android/ru-he-zheng-que-huo-de-androidnei-wai-sdqia-lu-jing

你可能感兴趣的:(获取SD卡地址 版本兼容)