安卓论坛
标题:
怎么SDCard上的获取相册照片
[打印本页]
作者:
admin
时间:
2016-1-6 20:30
标题:
怎么SDCard上的获取相册照片
private String getRealPathFromURI(Uri contentUri) {
Cursor cursor = null;
String result = contentUri.toString();
String[] proj = {MediaStore.Images.Media.DATA};
cursor = managedQuery(contentUri, proj, null, null, null);
if(cursor == null) throw new NullPointerException("reader file field");
if (cursor != null) {
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
// 最后根据索引值获取图片路径
result = cursor.getString(column_index);
try
{
//4.0以上的版本会自动关闭 (4.0--14;; 4.0.3--15)
if(Integer.parseInt(Build.VERSION.SDK) < 14)
{
cursor.close();
}
}catch(Exception e)
{
Log.e(TAG, "error:" + e);
}
}
return result;
}
复制代码
欢迎光临 安卓论坛 (http://android.hh85.com/)
Powered by Discuz! X3.2