Reputation: 559
Our app allows the user take pictures (and select pictures) from it.
I've used the Expo component ImagePicker for that, as it provides a simple API.
And it works perfectly inside expo (both exp start
and exp publish
), but it does not work within a standalone apk.
When I try to invoke ImagePicker.launchCameraAsync()
, I catch an EUNSPECIFIED exception, but that only in the standalone apk.
Details
An excerpt of the code:
import { ImagePicker } from 'expo';
(...)
const image = await ImagePicker.launchCameraAsync({
allowsEditing: true,
aspect: [3, 5],
});
(...)
let image = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
aspect: [3, 5],
});
It works well within expo, including exp publish
version.
As for my permissions in the app.json
, what I have is the following:
(...)
"android": {
"package": "br.com.miredefamilia",
"versionCode": 3,
"permissions": [
"android.permissions.CAMERA",
"android.permissions.READ_INTERNAL_STORAGE",
"android.permissions.READ_EXTERNAL_STORAGE"
]
}
I have also tried without the android.permissions
.
The mobile does request for the permission, I accept it, and it does not launch the camera / picker, like it does within the expo
.
Any help?
Upvotes: 0
Views: 2720
Reputation: 5428
This is the proper solution with docs link
Ask for Permission.CAMERA
and Permission.CAMERA_ROLL
const { status } = await Permissions.askAsync(Permissions.CAMERA, Permissions.CAMERA_ROLL)
if (status === 'granted') {
ImagePicker.launchCameraAsync({
mediaTypes: 'Images',
allowsEditing: true,
aspect: [1, 1]
})
} else {
// ask user to turn on permission here
}
Also update the app.json with this permissions
CAMERA
READ_EXTERNAL_STORAGE
READ_INTERNAL_STORAGE
Upvotes: 3
Reputation: 559
The following changes have fixed the problem:
In the app.json
"android": {
"package": "br.com.miredefamilia",
"versionCode": 3,
"permissions": [
"CAMERA",
"READ_INTERNAL_STORAGE",
"WRITE_INTERNAL_STORAGE",
"READ_EXTERNAL_STORAGE",
"WRITE_EXTERNAL_STORAGE"
]
}
And the calls to the component, I removed the parameters:
const image = await ImagePicker.launchCameraAsync();
let image = await ImagePicker.launchImageLibraryAsync();
I also removed the dependency:
"react-native-camera": "^0.10.0",
I don't know exactly which one solved the problem, but one of them did.
Upvotes: 2