Tell us which versions you are using:
Tell us to which platform this issue is related
Return image object
Returns nothing, promise is not fullfilled
can you try to debug this? I cannot reproduce it
on android 7/nexus 6P when you try to call camera, nothing happens
file:///storage/emulated/0/Pictures/image-c1fcccb4-e260-4f68-a7d4-e6b425a10e7a.jpg exposed beyond app through ClipData.Item.getUri()
at createErrorFromErrorData (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7367:11)
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7330:35
at MessageQueue.__invokeCallback (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7710:10)
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7562:8
at guard (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7481:1)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7561:1)
at message (file:///Applications/React%20Native%20Debugger.app/Contents/Resources/app.asar/js/debugger.worker.js:97:57)
Hey, i fixed my problem. I forgot to call super inside my overwritten onActivityResult method.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); <-- this line was missing
MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
}
@vitalyrotari your issue is described here http://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed. Do you have a time to submit PR for this issue?
@ivpusic thanks for help, camera works fine, below describes all changes
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
<application
...
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
private void initiateCamera(Activity activity) {
try {
int requestCode = CAMERA_PICKER_REQUEST;
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
tmpImage = true;
// we create a tmp file to save the result
File imageFile = createNewFile(true);
// mCameraCaptureURI = Uri.fromFile(imageFile);
mCameraCaptureURI = FileProvider.getUriForFile(activity,
activity.getApplicationContext().getPackageName() + ".provider",
imageFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraCaptureURI);
if (cameraIntent.resolveActivity(mReactContext.getPackageManager()) == null) {
mPickerPromise.reject(E_CANNOT_LAUNCH_CAMERA, "Cannot launch camera");
return;
}
activity.startActivityForResult(cameraIntent, requestCode);
} catch (Exception e) {
mPickerPromise.reject(E_FAILED_TO_OPEN_CAMERA, e);
}
}
but, when I press on accept photo, will take this error:
'_data' does not exist
at createErrorFromErrorData (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7367:11)
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7330:35
at MessageQueue.__invokeCallback (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7710:10)
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7562:8
at guard (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7481:1)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7561:1)
at message (file:///Applications/React%20Native%20Debugger.app/Contents/Resources/app.asar/js/debugger.worker.js:97:57)
My issue is solved.
issue solved, you can see modified PickerModule.java
@vitalyrotari did you maybe tried new PickerModule file with older Android versions? Does it still work?
@ivpusic I'll add some fixes for SDK 19, seems to work fine, will add final version a bit later ;)
I have the same issue.(ಥ_ಥ)
@ivpusic PickerModule Rev.4, tested and works on next SDK's:
I have the same problem. sdkVersion 23, buildtoolsVersion 23.0.1
@vitalyrotari After I've changed PickerModule.java to your version (PickerModule Rev.4)
and reinstalled on my device I'm now getting: "E_FAILED_TO_OPEN_CAMERA" :-(
@dudukenesto try to request permission before you call camera and look at this instructions
import { PermissionsAndroid } from 'react-native';
const granted = await PermissionsAndroid.requestPermission(
PermissionsAndroid.PERMISSIONS.CAMERA, {
title: 'Camera Access',
message: 'Your message here...'
}
);
if (granted) {
try {
const result = await ImagePicker
.openCamera({
width: 640,
height: 480,
cropping: false
});
} catch (e) {
// ...
}
}
Simply updating the package to the latest version fixed this for me.
@vitalyrotari I stand corrected.. your solution does fix the problem for "openCamera" function. Now it's working properly (yeaahh!) , BUT... with your code changes a new problem is created when using "openPicker" function. I get this error "E_NO_IMAGE_DATA_FOUND". With the original code this feature is working properly. So I guess I need to choose which feature is more important...
BTW, do you know of a component for choosing a file of any type from local storage? (not only images)
@dudukenesto yeah, sorry my bad :) I'll update, now must work fine camera and image picker
@vitalyrotari now everything is working. Thanks!
@vitalyrotari could you please try https://github.com/ivpusic/react-native-image-crop-picker/releases/tag/v0.10.2. I did small refactoring on top of your gist. Could you please try it on your devices to see if still everything works for you as well?
Thanks
@ivpusic all is working fine ;)