From a5befe328c850b696f62adf7b80f8ebfa7402529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Sun, 21 Mar 2021 04:34:01 +0100 Subject: [PATCH] fix: (Android) Fixed issue where timestamp was "0" (#277) --- .../cameraroll/CameraRollModule.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/reactnativecommunity/cameraroll/CameraRollModule.java b/android/src/main/java/com/reactnativecommunity/cameraroll/CameraRollModule.java index 65487e4ad..17883fdee 100644 --- a/android/src/main/java/com/reactnativecommunity/cameraroll/CameraRollModule.java +++ b/android/src/main/java/com/reactnativecommunity/cameraroll/CameraRollModule.java @@ -86,6 +86,8 @@ public class CameraRollModule extends ReactContextBaseJavaModule { Images.Media.MIME_TYPE, Images.Media.BUCKET_DISPLAY_NAME, Images.Media.DATE_TAKEN, + MediaStore.MediaColumns.DATE_ADDED, + MediaStore.MediaColumns.DATE_MODIFIED, MediaStore.MediaColumns.WIDTH, MediaStore.MediaColumns.HEIGHT, MediaStore.MediaColumns.SIZE, @@ -501,6 +503,8 @@ public class CameraRollModule extends ReactContextBaseJavaModule { int mimeTypeIndex = media.getColumnIndex(Images.Media.MIME_TYPE); int groupNameIndex = media.getColumnIndex(Images.Media.BUCKET_DISPLAY_NAME); int dateTakenIndex = media.getColumnIndex(Images.Media.DATE_TAKEN); + int dateAddedIndex = media.getColumnIndex(MediaStore.MediaColumns.DATE_ADDED); + int dateModifiedIndex = media.getColumnIndex(MediaStore.MediaColumns.DATE_MODIFIED); int widthIndex = media.getColumnIndex(MediaStore.MediaColumns.WIDTH); int heightIndex = media.getColumnIndex(MediaStore.MediaColumns.HEIGHT); int sizeIndex = media.getColumnIndex(MediaStore.MediaColumns.SIZE); @@ -520,7 +524,7 @@ public class CameraRollModule extends ReactContextBaseJavaModule { mimeTypeIndex, includeFilename, includeFileSize, includeImageSize, includePlayableDuration); if (imageInfoSuccess) { - putBasicNodeInfo(media, node, mimeTypeIndex, groupNameIndex, dateTakenIndex); + putBasicNodeInfo(media, node, mimeTypeIndex, groupNameIndex, dateTakenIndex, dateAddedIndex, dateModifiedIndex); putLocationInfo(media, node, dataIndex, includeLocation); edge.putMap("node", node); @@ -540,10 +544,18 @@ public class CameraRollModule extends ReactContextBaseJavaModule { WritableMap node, int mimeTypeIndex, int groupNameIndex, - int dateTakenIndex) { + int dateTakenIndex, + int dateAddedIndex, + int dateModifiedIndex) { node.putString("type", media.getString(mimeTypeIndex)); node.putString("group_name", media.getString(groupNameIndex)); - node.putDouble("timestamp", media.getLong(dateTakenIndex) / 1000d); + long dateTaken = media.getLong(dateTakenIndex); + if (dateTaken == 0L) { + //date added is in seconds, date taken in milliseconds, thus the multiplication + dateTaken = media.getLong(dateAddedIndex) * 1000; + } + node.putDouble("timestamp", dateTaken / 1000d); + node.putDouble("modified", media.getLong(dateModifiedIndex)); } /**