Guard against devices not supporting mandatory ContentProvider columns.

The docs specify that this column is supposed to be present, but a
crash says it wasn't, so alas, here in goes the check.
This commit is contained in:
Greyson Parrelli 2019-02-19 09:29:10 -08:00
parent c4d1bdc44d
commit 33daa21ad9

View File

@ -267,7 +267,7 @@ class MediaRepository {
if (size <= 0) { if (size <= 0) {
try (Cursor cursor = context.getContentResolver().query(media.getUri(), null, null, null, null)) { try (Cursor cursor = context.getContentResolver().query(media.getUri(), null, null, null, null)) {
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst() && cursor.getColumnIndex(OpenableColumns.SIZE) >= 0) {
size = cursor.getLong(cursor.getColumnIndexOrThrow(OpenableColumns.SIZE)); size = cursor.getLong(cursor.getColumnIndexOrThrow(OpenableColumns.SIZE));
} }
} }