I am trying to fetch all the photos of my android device.
I have an onCreate
function:
public void onCreate(Bundle savedInstanceState)
First do not forget to
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
This method will return list of photo in your gallery
public static ArrayList<String> getImagesPath(Activity activity) {
Uri uri;
ArrayList<String> listOfAllImages = new ArrayList<String>();
Cursor cursor;
int column_index_data, column_index_folder_name;
String PathOfImage = null;
uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String[] projection = { MediaColumns.DATA,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME };
cursor = activity.getContentResolver().query(uri, projection, null,
null, null);
column_index_data = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
column_index_folder_name = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
while (cursor.moveToNext()) {
PathOfImage = cursor.getString(column_index_data);
listOfAllImages.add(PathOfImage);
}
return listOfAllImages;
}
just give it a try even if your device has only internal storage no external storage,
try adding permissions:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
and read using
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;