mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
fix using deprecated constants in Android API Level 29
Summary: Changelog: [Internal] # Context FB4A recently updated from [Android API level 28 to level 29](https://fb.workplace.com/groups/782862961920333/permalink/1409529345920355/). This [deprecated](https://developer.android.com/reference/android/provider/MediaStore.Images.ImageColumns#LATITUDE) the constants `Images.Media.Latitude` and `Image.Media.Longitude`, and we started to get the exception found in the attached task. # This diff Similar to this [pull request](https://github.com/react-native-community/react-native-cameraroll/pull/170), it removes the usage of the deprecated latitude and longitude constants. However for our case I don't know if latitude and longitude are being used or not, so for this diff I will check on the Android API level before adding the latitude and longitude in the project list. This is a similar implementation to the [first version](https://github.com/react-native-community/react-native-cameraroll/pull/170/commits/adeeb3ee0aaeb79be3c6917f973c993ab4079868) of the above pull request where it checks the api level before extracting the location data. Differential Revision: D21774607 fbshipit-source-id: 632ea871b530b8e157f4ca74a5bc319b2abf7ba5
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5d39bfa501
commit
f29238cc0c
+29
-14
@@ -16,6 +16,7 @@ import android.media.MediaMetadataRetriever;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.MediaStore.Images;
|
||||
@@ -47,6 +48,7 @@ import java.nio.channels.Channels;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
// TODO #6015104: rename to something less iOSish
|
||||
@@ -68,22 +70,33 @@ public class CameraRollManager extends NativeCameraRollManagerSpec {
|
||||
private static final String ASSET_TYPE_VIDEOS = "Videos";
|
||||
private static final String ASSET_TYPE_ALL = "All";
|
||||
|
||||
private static final String[] PROJECTION = {
|
||||
Images.Media._ID,
|
||||
Images.Media.MIME_TYPE,
|
||||
Images.Media.BUCKET_DISPLAY_NAME,
|
||||
Images.Media.DATE_TAKEN,
|
||||
MediaStore.MediaColumns.WIDTH,
|
||||
MediaStore.MediaColumns.HEIGHT,
|
||||
Images.Media.LONGITUDE,
|
||||
Images.Media.LATITUDE,
|
||||
MediaStore.MediaColumns.DATA
|
||||
};
|
||||
|
||||
private static final String SELECTION_BUCKET = Images.Media.BUCKET_DISPLAY_NAME + " = ?";
|
||||
private static final String SELECTION_DATE_TAKEN = Images.Media.DATE_TAKEN + " < ?";
|
||||
private static final String SELECTION_MEDIA_SIZE = Images.Media.SIZE + " < ?";
|
||||
|
||||
private static final int IMAGES_MEDIA_LATITUDE_LONGITUDE_DEPRECATED_API_LEVEL = 29;
|
||||
private static final String[] PROJECTION_LIST;
|
||||
|
||||
static {
|
||||
ArrayList<String> projection_list =
|
||||
new ArrayList<>(
|
||||
Arrays.asList(
|
||||
Images.Media._ID,
|
||||
Images.Media.MIME_TYPE,
|
||||
Images.Media.BUCKET_DISPLAY_NAME,
|
||||
Images.Media.DATE_TAKEN,
|
||||
MediaStore.MediaColumns.WIDTH,
|
||||
MediaStore.MediaColumns.HEIGHT,
|
||||
MediaStore.MediaColumns.DATA));
|
||||
if (Build.VERSION.SDK_INT < IMAGES_MEDIA_LATITUDE_LONGITUDE_DEPRECATED_API_LEVEL) {
|
||||
projection_list.add(Images.Media.LATITUDE);
|
||||
projection_list.add(Images.Media.LONGITUDE);
|
||||
PROJECTION_LIST = projection_list.toArray(new String[0]);
|
||||
} else {
|
||||
PROJECTION_LIST = projection_list.toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public CameraRollManager(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
}
|
||||
@@ -351,7 +364,7 @@ public class CameraRollManager extends NativeCameraRollManagerSpec {
|
||||
Cursor media =
|
||||
resolver.query(
|
||||
MediaStore.Files.getContentUri("external"),
|
||||
PROJECTION,
|
||||
PROJECTION_LIST,
|
||||
selection.toString(),
|
||||
selectionArgs.toArray(new String[selectionArgs.size()]),
|
||||
Images.Media.DATE_TAKEN
|
||||
@@ -413,7 +426,9 @@ public class CameraRollManager extends NativeCameraRollManagerSpec {
|
||||
resolver, media, node, idIndex, widthIndex, heightIndex, dataIndex, mimeTypeIndex);
|
||||
if (imageInfoSuccess) {
|
||||
putBasicNodeInfo(media, node, mimeTypeIndex, groupNameIndex, dateTakenIndex);
|
||||
putLocationInfo(media, node, longitudeIndex, latitudeIndex);
|
||||
if (Build.VERSION.SDK_INT < IMAGES_MEDIA_LATITUDE_LONGITUDE_DEPRECATED_API_LEVEL) {
|
||||
putLocationInfo(media, node, longitudeIndex, latitudeIndex);
|
||||
}
|
||||
|
||||
edge.putMap("node", node);
|
||||
edges.pushMap(edge);
|
||||
|
||||
Reference in New Issue
Block a user