Android内置和外置SD卡的位置获取
- public class StorageUtils {
- private static String TAG="123";
- // 获取主存储卡路径 内置内存卡路径
- public static String getPrimaryStoragePath(Context context) {
- try {
- StorageManager sm = (StorageManager) context.getSystemService(context.STORAGE_SERVICE);
- Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths");
- String[] paths = (String[]) getVolumePathsMethod.invoke(sm);
- // first element in paths[] is primary storage path
- return paths[0];
- } catch (Exception e) {
- Log.e(TAG, "getPrimaryStoragePath() failed", e);
- }
- return null;
- }
- //获取可用的所有外置内存卡路径
- public static List<String> getSecondaryStoragePath(Context context) {
- try {
- List<String> sdPaths=new ArrayList<>();
- StorageManager sm = (StorageManager) context.getSystemService(context.STORAGE_SERVICE);
- Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths");
- String[] paths = (String[]) getVolumePathsMethod.invoke(sm);//获取所有sd卡路径
- if(paths.length>=1){
- for (int i = 1; i <paths.length ; i++) {
- if(getStorageState(context,paths[i])){
- sdPaths.add(paths[i]);
- }
- }
- }
- return sdPaths;
- } catch (Exception e) {
- Log.e(TAG, "getSecondaryStoragePath() failed", e);
- }
- return null;
- }
- // 判断存储卡的路径是否可用
- public static boolean getStorageState(Context context,String path) {
- try {
- StorageManager sm = (StorageManager) context.getSystemService(context.STORAGE_SERVICE);
- Method getVolumeStateMethod = StorageManager.class.getMethod("getVolumeState", new Class[] {String.class});
- String state = (String) getVolumeStateMethod.invoke(sm, path);
- if(state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)||state.equals(Environment.MEDIA_MOUNTED)){
- return true;
- }
- return false;
- } catch (Exception e) {
- Log.e(TAG, "getStorageState() failed", e);
- return false;
- }
- }
- }
Android内置和外置SD卡的位置获取的更多相关文章
- android获取内置和外置SD卡路径 - z
本文将介绍Android真机环境下如何获取内置和外置SD卡路径. 测试环境:三星Note3,其他手机待测试... 所需权限(AndroidManifest.xml文件里) <uses-permi ...
- Android手机外置SD卡(TF卡)的获取方法
Android手机上的外置SD卡,起初的时候,即在Android出世的前几年,那时手机的存储是十分有限的,不像现在到处可见16G.32G和64G的存储,因而那时候的手机有的厂商允许插入外置的SD卡,此 ...
- Android开发获取多个存储空间的路径(内置SD卡以及外置SD卡)
Android开发中经常会遇到多存储空间的问题,包括内置存储路径以及外置SD卡,而且有的时候会有多张外置SD卡,此时就需要获取不同的SD卡路径,然后根据需要来写入或者读出文件. 此处给出常用的SD卡工 ...
- 关于手机的内置SD卡与外置SD卡
对于安卓2.3的系统来说,Environment.getExternalStorageDirectory()获取的目录是内置SD卡还是外置SD卡是无法保证的, 和手机厂商的修改有关,只能通过Envir ...
- android4.0 中关于内外置sd卡的获取及读写权限问题
from://http://blog.chinaunix.net/uid-26727976-id-3146895.html 在2.x的版本中,在manifest中配置的权限android.permis ...
- Android 5.1.1在外置SD卡中创建文件夹
Android 4.4之后WRITE_MEDIA_STORAGE 权限仅提供给系统应用,不再授予第三方App,WRITE_EXTERNAL_STORAGE 权限,仅仅用于授权用户写 primary e ...
- Android操作外置SD卡和U盘相关文章
Android设备与外接U盘实现数据读取操作https://blog.csdn.net/true100/article/details/77775700 usbdisklibhttps://githu ...
- Android应用正确使用扩展SD卡,特别是安卓4.4以后的版本
Android 开发时如何正确获取使用扩展存储路径 在 2.x 版本中,Android设备都是单存储,第三方App写文件,必须申请 WRITE_EXTERNAL_STORAGE 权限: 在4.0之后, ...
- Android 下载文件及写入SD卡
Android 下载文件及写入SD卡,实例代码 <?xml version="1.0" encoding="utf-8"?> <LinearL ...
随机推荐
- python3之scrapy安装使用
需要安装的包 pip install scrapy selenium 可能需要卸载重装的模块 lxml cryptography cffi pypiwin32 pip uninstall xx ...
- JMS可靠性机制
1. 消息接收确认 JMS消息只有在被确认之后,才认为已经被成功的消费了,消息的成功消费通常包含三个阶段:客户接收消息,客户处理消息和消息被确认 在事务性会话中,当一个事务被提交的时候,确认自动发生. ...
- CAN总线扩展数据帧介绍
在扩展CAN 数据帧中,紧随SOF 位的是32 位的仲裁字段.仲裁字段的前11 位为29 位标识符的最高有效位(Most Significant bit,MSb)(基本lD) .紧随这11 位的是替代 ...
- FPGA前世今生(一)
关于FPGA,我想做硬件的或多或少都听过.从上世纪80年代算来,FPGA已走过了30多个年头.我们以FPGA两大生产厂商,两大巨头之一的INTEL(altera)公司的FPGA为例,为大家逐步介绍FP ...
- appstore 上传需要的icon
<key>CFBundleIconFiles</key><array> <string>icon@2x.png</string> <s ...
- Unity Shader入门教程(三)自制光照模型
光照模型的概念目前还不明晰,因为笔者也是一个初学者,所以请小心对待笔者介绍的内容.笔者认为光照模型是规定光照算法的模型,比如说前面提到的Lambert光照模型,规定了材质表面的光线的表达式为 环境光+ ...
- microtime() 测试代码执行时间,提高编码效率
<?php $b_time = microtime(true); $a = array("); $count = ; foreach ($a as $key => $value) ...
- 列举不少于6条的IE与FF脚本兼容性问题,需要写出命令
(1) window.event: 表示当前的事件对象,IE有这个对象,FF没有,FF通过给事件处理函数传递事件对象 (2) 获取事件源 IE用srcElement获取事件源,而FF用target获取 ...
- Python Twisted系列教程15:测试诗歌
作者:dave@http://krondo.com/tested-poetry/ 译者: Cheng Luo 你可以从”第一部分 Twist理论基础“开始阅读:也可以从”Twisted 入门!“浏览 ...
- Windows 环境下Java调用CRF++详解
1.步骤一览 2.步骤详情 2.1.环境准备 Swig(Simplified Wrapper and Interface Generator)下载,Windows操作系统直接解压即可使用 CRF++( ...