Skip to content

Commit a324dfb

Browse files
fred2028facebook-github-bot
authored andcommitted
Allow Android videos to be shown in the CameraRoll selector
Summary: Currently, Android camera roll videos cannot be retrieved in RN since 1) `CameraRollManager.java` doesn't do anything with the `assetType` param 2) Unspecifying MIME types doesn't show videos This diff allows videos to be shown in the `CameraRoll.getPhotos(..)` call by reading `assetType`. Future diffs will come where the thumbnail and other info will be returned as well. Reviewed By: furdei Differential Revision: D5019202 fbshipit-source-id: a920273761b31f1a59ba6b8bc49c05852506829c
1 parent d40a7ea commit a324dfb

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

ReactAndroid/src/main/java/com/facebook/react/modules/camera/CameraRollManager.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import android.os.Environment;
3232
import android.provider.MediaStore;
3333
import android.provider.MediaStore.Images;
34+
import android.provider.MediaStore.Video;
3435
import android.text.TextUtils;
3536

3637
import com.facebook.common.logging.FLog;
@@ -213,6 +214,10 @@ public void onScanCompleted(String path, Uri uri) {
213214
* mimeType (optional): restrict returned images to a specific mimetype (e.g.
214215
* image/jpeg)
215216
* </li>
217+
* <li>
218+
* assetType (optional): chooses between either photos or videos from the camera roll.
219+
* Valid values are "Photos" or "Videos". Defaults to photos.
220+
* </li>
216221
* </ul>
217222
* @param promise the Promise to be resolved when the photos are loaded; for a format of the
218223
* parameters passed to this callback, see {@code getPhotosReturnChecker} in CameraRoll.js
@@ -222,6 +227,7 @@ public void getPhotos(final ReadableMap params, final Promise promise) {
222227
int first = params.getInt("first");
223228
String after = params.hasKey("after") ? params.getString("after") : null;
224229
String groupName = params.hasKey("groupName") ? params.getString("groupName") : null;
230+
String assetType = params.hasKey("assetType") ? params.getString("assetType") : null;
225231
ReadableArray mimeTypes = params.hasKey("mimeTypes")
226232
? params.getArray("mimeTypes")
227233
: null;
@@ -235,6 +241,7 @@ public void getPhotos(final ReadableMap params, final Promise promise) {
235241
after,
236242
groupName,
237243
mimeTypes,
244+
assetType,
238245
promise)
239246
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
240247
}
@@ -246,13 +253,15 @@ private static class GetPhotosTask extends GuardedAsyncTask<Void, Void> {
246253
private final @Nullable String mGroupName;
247254
private final @Nullable ReadableArray mMimeTypes;
248255
private final Promise mPromise;
256+
private final @Nullable String mAssetType;
249257

250258
private GetPhotosTask(
251259
ReactContext context,
252260
int first,
253261
@Nullable String after,
254262
@Nullable String groupName,
255263
@Nullable ReadableArray mimeTypes,
264+
@Nullable String assetType,
256265
Promise promise) {
257266
super(context);
258267
mContext = context;
@@ -261,6 +270,7 @@ private GetPhotosTask(
261270
mGroupName = groupName;
262271
mMimeTypes = mimeTypes;
263272
mPromise = promise;
273+
mAssetType = assetType;
264274
}
265275

266276
@Override
@@ -289,8 +299,12 @@ protected void doInBackgroundGuarded(Void... params) {
289299
// setting a limit at all), but it works because this specific ContentProvider is backed by
290300
// an SQLite DB and forwards parameters to it without doing any parsing / validation.
291301
try {
302+
Uri assetURI =
303+
mAssetType != null && mAssetType.equals("Videos") ? Video.Media.EXTERNAL_CONTENT_URI :
304+
Images.Media.EXTERNAL_CONTENT_URI;
305+
292306
Cursor photos = resolver.query(
293-
Images.Media.EXTERNAL_CONTENT_URI,
307+
assetURI,
294308
PROJECTION,
295309
selection.toString(),
296310
selectionArgs.toArray(new String[selectionArgs.size()]),

0 commit comments

Comments
 (0)