搜索
热搜: 活动 交友 discuz
查看: 3603|回复: 0
打印 上一主题 下一主题

怎么SDCard上的获取相册照片

[复制链接]

160

主题

165

帖子

814

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
814
跳转到指定楼层
楼主
发表于 2016-1-6 20:30:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. private String getRealPathFromURI(Uri contentUri) {
  2.                 Cursor cursor = null;
  3.                 String result = contentUri.toString();
  4.                 String[] proj = {MediaStore.Images.Media.DATA};
  5.                 cursor = managedQuery(contentUri, proj, null, null, null);
  6.                 if(cursor == null) throw new NullPointerException("reader file field");
  7.                 if (cursor != null) {
  8.                         int column_index = cursor
  9.                                         .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
  10.                         cursor.moveToFirst();
  11.                         // 最后根据索引值获取图片路径
  12.                         result = cursor.getString(column_index);
  13.                          try  
  14.                     {  
  15.                         //4.0以上的版本会自动关闭 (4.0--14;; 4.0.3--15)  
  16.                         if(Integer.parseInt(Build.VERSION.SDK) < 14)  
  17.                         {  
  18.                             cursor.close();  
  19.                         }  
  20.                     }catch(Exception e)  
  21.                     {  
  22.                         Log.e(TAG, "error:" + e);  
  23.                     }  
  24.                 }
  25.                 return result;
  26.     }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|安卓论坛  

GMT+8, 2024-5-19 16:09 , Processed in 0.054692 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2013 Design S!|ƽ̶

快速回复 返回顶部 返回列表