2
MediaStore에 이미지 ID가 있습니다. ID로 갤러리의 이미지를 어떻게 볼 수 있습니까?android에서 이미지 ID를 통해 이미지를 보는 방법
ContentResolver cr = context.getContentResolver();
String columns[] = new String[]{
Media._ID, Media.DATA
};
Cursor cursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, Media._ID+"=?", new String[]{id+""}, null);
if(cursor.moveToNext()) {
String imagePath = cursor.getString(cursor.getColumnIndex(Media.DATA));
Uri imageUri = Uri.fromFile(new File(imagePath));
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.addCategory(android.content.Intent.CATEGORY_DEFAULT);
intent.setDataAndType(imageUri, "image/*");
((Activity)context).startActivity(intent);
}
그것은 작동하지만 너무 성가신 : 나는 현재 다음 코드를 사용합니다. 나는 이것을하기위한 더 쉬운 방법이 있어야한다고 생각한다. 열쇠는 이미지 ID에서 Uri 이미지를 가져 오는 것입니다.
열린 URI = Uri.withAppendedPath (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 가지는 Integer.toString (imageID)); 그게 내가 필요한거야. 정말 고맙습니다! –
나는 당신이 긴 imageId = blah를 사용한다고 생각한다 ... 그러나 이것은 나의 질문에 대답했다. – danny117