how to get all images and photos from my android device not from sdcard?
-
20-06-2021 - |
Question
i would like to get all images/photos/wallpapers from my android device with image saved path.
I have implemented code for collect the images from sdcard as follows:
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);
from the above code i can able to retrive the images from sdcard only.But if the images are available in device phone memory then how can i retrive the images/photos/wallpapers? If i use INTERNAL_CONTENT_URI it is not returning wallapers info other images information
please any body help me....
Solution
Try this answer this will work:
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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow