当前位置: 移动技术网 > IT编程>移动开发>Android > 获取android4.0版本sdcard路径示例

获取android4.0版本sdcard路径示例

2019年07月24日  | 移动技术网IT编程  | 我要评论

影后之舞,考拉理财,大炎魔

复制代码 代码如下:

@suppresslint("newapi")//你懂的
private file findsdcard() {
 boolean b = environment.media_mounted.equals(environment
   .getexternalstoragestate());
 if (!b) return null;

    file extfile = environment.getexternalstoragedirectory();
 file[] files = extfile.listfiles();
 if (files == null)
  return null;
 for (file f : files) {
  if (extfile.isdirectory()
    && f.canwrite()//sd卡一定是可写的.如果去掉这条件的话会得到隐藏的系统专用文件夹
    && math.abs(extfile.gettotalspace() - f.gettotalspace()) > 2 * 1024 * 1024) {
    //外部存储器与子目录的在未挂载的情况下有相同的存储容量.子目录是挂载的话.就会出现不同的存储容量
    //2 * 1024 * 1024 是用来指出两存储器的存储容量大小差异 当然可以不用这么大 随意
   return f;
  }
 }
 return null;
}

        //调用,14为android4.0
  if (build.version.sdk_int >= 14) {
  file sd = findsdcard(extfile);
  }

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网