Skip to content
Permalink
Browse files
Fixed NullPointer Exception in Android 5 and above due to invalid col…
…umn name on cursor
  • Loading branch information
aroberson authored and stevengill committed Nov 9, 2015
1 parent 2c0d885 commit 53835beb93cca3e549b6750c727a6fbdc8c61309
Showing 1 changed file with 9 additions and 4 deletions.
@@ -127,7 +127,9 @@ public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws
try {
if (cursor != null && cursor.moveToFirst()) {
size = resourceSizeForCursor(cursor);
lastModified = lastModifiedDateForCursor(cursor);
Long modified = lastModifiedDateForCursor(cursor);
if (modified != null)
lastModified = modified.longValue();
} else {
// Some content providers don't support cursors at all!
CordovaResourceApi.OpenForReadResult offr = resourceApi.openForRead(nativeUri);
@@ -185,12 +187,15 @@ private Long resourceSizeForCursor(Cursor cursor) {
}

protected Long lastModifiedDateForCursor(Cursor cursor) {
final String[] LOCAL_FILE_PROJECTION = { MediaStore.MediaColumns.DATE_MODIFIED };
int columnIndex = cursor.getColumnIndex(LOCAL_FILE_PROJECTION[0]);
int columnIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DATE_MODIFIED);
if (columnIndex == -1) {
columnIndex = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_LAST_MODIFIED);
}
if (columnIndex != -1) {
String dateStr = cursor.getString(columnIndex);
if (dateStr != null) {
return Long.parseLong(dateStr);
if (dateStr != null) {
return Long.parseLong(dateStr);
}
}
return null;

0 comments on commit 53835be

Please sign in to comment.