consider images and videos too when listing directories
This commit is contained in:
parent
75da6ec678
commit
39fa01ab96
1 changed files with 29 additions and 24 deletions
|
@ -128,11 +128,15 @@ public class MainActivity extends AppCompatActivity
|
||||||
|
|
||||||
private Map<String, Directory> getDirectories() {
|
private Map<String, Directory> getDirectories() {
|
||||||
final Map<String, Directory> directories = new LinkedHashMap<>();
|
final Map<String, Directory> directories = new LinkedHashMap<>();
|
||||||
final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
final List<String> invalidFiles = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||||
|
if (i == 1) {
|
||||||
|
uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
||||||
|
}
|
||||||
final String[] columns = {MediaStore.Images.Media.DATA};
|
final String[] columns = {MediaStore.Images.Media.DATA};
|
||||||
final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC";
|
final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC";
|
||||||
final Cursor cursor = getContentResolver().query(uri, columns, null, null, order);
|
final Cursor cursor = getContentResolver().query(uri, columns, null, null, order);
|
||||||
final List<String> invalidFiles = new ArrayList<>();
|
|
||||||
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
||||||
|
@ -157,6 +161,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final String[] invalids = invalidFiles.toArray(new String[invalidFiles.size()]);
|
final String[] invalids = invalidFiles.toArray(new String[invalidFiles.size()]);
|
||||||
MediaScannerConnection.scanFile(getApplicationContext(), invalids, null, null);
|
MediaScannerConnection.scanFile(getApplicationContext(), invalids, null, null);
|
||||||
|
|
Loading…
Reference in a new issue