I am using mediastore to read the list of subfolders of the Music folder as shown below. However, the list that has not been deleted from my app remains in the list even if the file does not exist. I want to know how to read only the list of files that have files in a folder. thank you
public void getFileListInFolderApiQ(String path) {
Uri externalUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.MediaColumns.RELATIVE_PATH + "=?";
String[] selectionArgs = new String[]{Environment.DIRECTORY_MUSIC + "/" + "data" + "/"};
String[] projection = new String[]{
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.MIME_TYPE
};
Cursor cursor = getContentResolver().query(externalUri, projection, selection, selectionArgs, null);
Uri testUri = null;
if (cursor == null || !cursor.moveToFirst()) {
return;
}
do {
String contentUrl = externalUri.toString() + "/" + cursor.getString(0);
long id = cursor.getLong(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
Uri uri = ContentUris.withAppendedId(externalUri, id);
String tmpFilename = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME));
testUri = uri;
// add list
} while (cursor.moveToNext());
}