I simply want to query all of the files from a folder called memories
. I have tried looking at the following links but couldn't find anything appropriate or 'working'.
- https://android.jlelse.eu/handling-files-in-code-after-the-android-10-released-2bea0e16d35
- https://developer.android.com/training/data-storage/shared/media#query-collection
- How to I read and write a txt file from android 10 and above from internal storage
- How to get the path of a specific folder in Android Q
EDIT: Abs Path: imageUri: content://media/external/images/media/31
EDIT: How I save the image:
private void saveImage(Bitmap bitmap, @NonNull String name) throws IOException {
boolean saved;
OutputStream fos;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ContentResolver resolver = getContext().getContentResolver();
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, name);
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/png");
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, "DCIM/" + IMAGES_FOLDER_NAME);
Uri imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
Log.d(TAG, "imageUri: " + imageUri);
fos = resolver.openOutputStream(imageUri);
} else {
String imagesDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DCIM).toString() + File.separator + IMAGES_FOLDER_NAME;
File file = new File(imagesDir);
if (!file.exists()) {
file.mkdir();
}
File image = new File(imagesDir, name + ".png");
Log.d(TAG, "File file: " + image);
fos = new FileOutputStream(image);
}
saved = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
Log.d(TAG, "Bitmap Image AndroidQ: " + saved);
fos.flush();
fos.close();
}