mirror of
https://github.com/status-im/react-native-cameraroll.git
synced 2025-02-17 12:06:40 +00:00
saveToCameraRoll should use DCIM folder
Summary: The DCIM folder is a better mapping to a "CameraRoll" than the "movies" or "pictures" directories. https://developer.android.com/reference/android/os/Environment.html#DIRECTORY_DCIM ``` DIRECTORY_DCIM The traditional location for pictures and videos when mounting the device as a camera. Note that this is primarily a convention for the top-level public directory, as this convention makes no sense elsewhere. ``` **Test plan** - Make sure tests pass on both Travis and Circle CI. - Test `saveToCameraRoll` in an example app, and check it is saved to the expected folder in a photos app. Closes https://github.com/facebook/react-native/pull/12059 Differential Revision: D4500946 Pulled By: mkonicek fbshipit-source-id: 8af994492303c175374502dffe6fd2f3e4e9975e
This commit is contained in:
parent
1a8b4d8689
commit
c34ffb9fd9
@ -115,25 +115,21 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
|
||||
*/
|
||||
@ReactMethod
|
||||
public void saveToCameraRoll(String uri, String type, Promise promise) {
|
||||
MediaType parsedType = type.equals("video") ? MediaType.VIDEO : MediaType.PHOTO;
|
||||
new SaveToCameraRoll(getReactApplicationContext(), Uri.parse(uri), parsedType, promise)
|
||||
new SaveToCameraRoll(getReactApplicationContext(), Uri.parse(uri), promise)
|
||||
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
private enum MediaType { PHOTO, VIDEO };
|
||||
private static class SaveToCameraRoll extends GuardedAsyncTask<Void, Void> {
|
||||
|
||||
private final Context mContext;
|
||||
private final Uri mUri;
|
||||
private final Promise mPromise;
|
||||
private final MediaType mType;
|
||||
|
||||
public SaveToCameraRoll(ReactContext context, Uri uri, MediaType type, Promise promise) {
|
||||
public SaveToCameraRoll(ReactContext context, Uri uri, Promise promise) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
mUri = uri;
|
||||
mPromise = promise;
|
||||
mType = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -141,9 +137,7 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
|
||||
File source = new File(mUri.getPath());
|
||||
FileChannel input = null, output = null;
|
||||
try {
|
||||
File exportDir = (mType == MediaType.PHOTO)
|
||||
? Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
|
||||
: Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);
|
||||
File exportDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
|
||||
exportDir.mkdirs();
|
||||
if (!exportDir.isDirectory()) {
|
||||
mPromise.reject(ERROR_UNABLE_TO_LOAD, "External media storage directory not available");
|
||||
|
Loading…
x
Reference in New Issue
Block a user