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 ccb0899658
commit 1748922c15
1 changed files with 22 additions and 20 deletions

View File

@ -9,16 +9,6 @@
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.Context;
import android.content.res.AssetFileDescriptor;
@ -33,16 +23,15 @@ import android.provider.MediaStore;
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Video;
import android.text.TextUtils;
import com.facebook.common.logging.FLog;
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.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
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.ReadableMap;
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.common.ReactConstants;
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
/**
@ -314,7 +311,7 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
mPromise.reject(ERROR_UNABLE_TO_LOAD, "Could not get photos");
} else {
try {
putEdges(resolver, photos, response, mFirst);
putEdges(resolver, photos, response, mFirst, mAssetType);
putPageInfo(photos, response, mFirst);
} finally {
photos.close();
@ -346,7 +343,8 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
ContentResolver resolver,
Cursor photos,
WritableMap response,
int limit) {
int limit,
@Nullable String assetType) {
WritableArray edges = new WritableNativeArray();
photos.moveToFirst();
int idIndex = photos.getColumnIndex(Images.Media._ID);
@ -362,7 +360,7 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
WritableMap edge = new WritableNativeMap();
WritableMap node = new WritableNativeMap();
boolean imageInfoSuccess =
putImageInfo(resolver, photos, node, idIndex, widthIndex, heightIndex);
putImageInfo(resolver, photos, node, idIndex, widthIndex, heightIndex, assetType);
if (imageInfoSuccess) {
putBasicNodeInfo(photos, node, mimeTypeIndex, groupNameIndex, dateTakenIndex);
putLocationInfo(photos, node, longitudeIndex, latitudeIndex);
@ -396,11 +394,15 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
WritableMap node,
int idIndex,
int widthIndex,
int heightIndex) {
int heightIndex,
@Nullable String assetType) {
WritableMap image = new WritableNativeMap();
Uri photoUri = Uri.withAppendedPath(
Images.Media.EXTERNAL_CONTENT_URI,
photos.getString(idIndex));
Uri photoUri;
if (assetType != null && assetType.equals("Videos")) {
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());
float width = -1;
float height = -1;