我想通过图片保存路径从我的Android设备获取所有图像/照片/壁纸。
我已经实现了从sdcard收集图像的代码,如下所示:
String[] mProjection = {
MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA
};
mCursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
mProjection,
null,
null,
MediaStore.Images.Media.DEFAULT_SORT_ORDER);
从上面的代码我只能从sdcard中检索图像。但是如果图像在设备手机内存中可用,那么我该如何检索图像/照片/壁纸? 如果我使用INTERNAL_CONTENT_URI它不会返回wallapers info其他图像信息
请任何人帮助我......
答案 0 :(得分:0)
尝试这个答案,这将有效:
public static final int GALLERY_CODE = 322;
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(
intent,
"Select Picture"),
GALLERY_CODE);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//Assinging on corresponding import
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GALLERY_CODE && resultCode == RESULT_OK) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
try {
//add logic for coping file
} catch (Exception e) {
}
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}