Permalink
Browse files

Retrieve correct content uri for videos

Reviewed By: furdei

Differential Revision: D5547060

fbshipit-source-id: 6d3a6273ffbaa179081254e46204211b31faacf2
  • Loading branch information...
Nivetha Singara Vadivelu authored and facebook-github-bot committed Aug 3, 2017
1 parent ccb0899 commit 1748922c15b714636f1b6730a6fed9df9ac72001
Showing with 22 additions and 20 deletions.
  1. +22 −20 ReactAndroid/src/main/java/com/facebook/react/modules/camera/CameraRollManager.java
@@ -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.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.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 @@ protected void doInBackgroundGuarded(Void... params) {
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 @@ private static void putEdges(
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 @@ private static void putEdges(
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 @@ private static boolean putImageInfo(
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;

0 comments on commit 1748922

Please sign in to comment.