Retrieve correct content uri for videos

Reviewed By: furdei

Differential Revision: D5547060

fbshipit-source-id: 6d3a6273ffbaa179081254e46204211b31faacf2
This commit is contained in:
Nivetha Singara Vadivelu 2017-08-02 19:59:54 -07:00 committed by Facebook Github Bot
parent b88425488f
commit 67cb90071d
1 changed files with 22 additions and 20 deletions

View File

@ -9,16 +9,6 @@
package com.facebook.react.modules.camera; package com.facebook.react.modules.camera;
import javax.annotation.Nullable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.res.AssetFileDescriptor; import android.content.res.AssetFileDescriptor;
@ -33,16 +23,15 @@ import android.provider.MediaStore;
import android.provider.MediaStore.Images; import android.provider.MediaStore.Images;
import android.provider.MediaStore.Video; import android.provider.MediaStore.Video;
import android.text.TextUtils; import android.text.TextUtils;
import com.facebook.common.logging.FLog; import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.GuardedAsyncTask; import com.facebook.react.bridge.GuardedAsyncTask;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableArray;
@ -51,6 +40,14 @@ import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.bridge.WritableNativeMap; import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.common.ReactConstants; import com.facebook.react.common.ReactConstants;
import com.facebook.react.module.annotations.ReactModule; import com.facebook.react.module.annotations.ReactModule;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
// TODO #6015104: rename to something less iOSish // TODO #6015104: rename to something less iOSish
/** /**
@ -314,7 +311,7 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
mPromise.reject(ERROR_UNABLE_TO_LOAD, "Could not get photos"); mPromise.reject(ERROR_UNABLE_TO_LOAD, "Could not get photos");
} else { } else {
try { try {
putEdges(resolver, photos, response, mFirst); putEdges(resolver, photos, response, mFirst, mAssetType);
putPageInfo(photos, response, mFirst); putPageInfo(photos, response, mFirst);
} finally { } finally {
photos.close(); photos.close();
@ -346,7 +343,8 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
ContentResolver resolver, ContentResolver resolver,
Cursor photos, Cursor photos,
WritableMap response, WritableMap response,
int limit) { int limit,
@Nullable String assetType) {
WritableArray edges = new WritableNativeArray(); WritableArray edges = new WritableNativeArray();
photos.moveToFirst(); photos.moveToFirst();
int idIndex = photos.getColumnIndex(Images.Media._ID); int idIndex = photos.getColumnIndex(Images.Media._ID);
@ -362,7 +360,7 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
WritableMap edge = new WritableNativeMap(); WritableMap edge = new WritableNativeMap();
WritableMap node = new WritableNativeMap(); WritableMap node = new WritableNativeMap();
boolean imageInfoSuccess = boolean imageInfoSuccess =
putImageInfo(resolver, photos, node, idIndex, widthIndex, heightIndex); putImageInfo(resolver, photos, node, idIndex, widthIndex, heightIndex, assetType);
if (imageInfoSuccess) { if (imageInfoSuccess) {
putBasicNodeInfo(photos, node, mimeTypeIndex, groupNameIndex, dateTakenIndex); putBasicNodeInfo(photos, node, mimeTypeIndex, groupNameIndex, dateTakenIndex);
putLocationInfo(photos, node, longitudeIndex, latitudeIndex); putLocationInfo(photos, node, longitudeIndex, latitudeIndex);
@ -396,11 +394,15 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
WritableMap node, WritableMap node,
int idIndex, int idIndex,
int widthIndex, int widthIndex,
int heightIndex) { int heightIndex,
@Nullable String assetType) {
WritableMap image = new WritableNativeMap(); WritableMap image = new WritableNativeMap();
Uri photoUri = Uri.withAppendedPath( Uri photoUri;
Images.Media.EXTERNAL_CONTENT_URI, if (assetType != null && assetType.equals("Videos")) {
photos.getString(idIndex)); photoUri = Uri.withAppendedPath(Video.Media.EXTERNAL_CONTENT_URI, photos.getString(idIndex));
} else {
photoUri = Uri.withAppendedPath(Images.Media.EXTERNAL_CONTENT_URI, photos.getString(idIndex));
}
image.putString("uri", photoUri.toString()); image.putString("uri", photoUri.toString());
float width = -1; float width = -1;
float height = -1; float height = -1;