Unfortunately App has stopped (crashed)
See original GitHub issueHello everyone, i had installed and implemented the react-native-image-picker correctly, but when testing it on the emulator or the device the app crashes badly and i get this error “Unfortunately app has stopped”.
I’m using react native v0.31 / RN-image-picker latest version 0.22.10 / testing device (android 5), emulator (android 7).
Here is the settings.gradle: `ootProject.name = ‘NativeStarterKit’
include ‘:app’ include ‘:react-native-datetime’ project(‘:react-native-datetime’).projectDir = new File(rootProject.projectDir, ‘…/node_modules/react-native-datetime/android’) include ‘:react-native-contacts’ project(‘:react-native-contacts’).projectDir = new File(rootProject.projectDir, ‘…/node_modules/react-native-contacts/android’) include ‘:cordovaplugin’ project(‘:cordovaplugin’).projectDir = new File(rootProject.projectDir, ‘…/node_modules/react-native-cordova-plugin/framework/android’) include ‘:react-native-datetime-picker’ project(‘:react-native-datetime-picker’).projectDir = new File(rootProject.projectDir, ‘…/node_modules/@remobile/react-native-datetime-picker/android’) include ‘:react-native-vector-icons’ project(‘:react-native-vector-icons’).projectDir = new File(rootProject.projectDir, ‘…/node_modules/react-native-vector-icons/android’) include ‘:react-native-splash-screen’ project(‘:react-native-splash-screen’).projectDir = new File(rootProject.projectDir, ‘…/node_modules/react-native-splash-screen/android’) include ‘:react-native-spinkit’ project(‘:react-native-spinkit’).projectDir = new File(rootProject.projectDir, ‘…/node_modules/react-native-spinkit/android’) include ‘:react-native-image-picker’ project(‘:react-native-image-picker’).projectDir = new File(rootProject.projectDir, ‘…/node_modules/react-native-image-picker/android’) include ‘:react-native-fetch-blob’ project(‘:react-native-fetch-blob’).projectDir = new File(rootProject.projectDir, ‘…/node_modules/react-native-fetch-blob/android’)`
Here is the manifest file: `<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.nativestarterkit" android:versionCode="1" android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />
<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"
>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" /><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
`
and finally this is how i implemented this plugin inside mycode:
<Button style={{height:75, marginTop:50, marginLeft:40, width:75, borderRadius: 100/2}} onPress={() => this.launchCamera()}> <Icon name='camera' size={45} style={{color:'white'}}/> </Button>
` launchCamera() {
ImagePicker.launchCamera(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
}
else if (response.error) {
console.log('ImagePicker Error: ', response.error);
}
else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
}
else {
// You can display the image using either data...
const source = {uri: 'data:image/jpeg;base64,' + response.data, isStatic: true};
// or a reference to the platform specific asset location
if (Platform.OS === 'ios') {
const source = {uri: response.uri.replace('file://', ''), isStatic: true};
} else {
const source = {uri: response.uri, isStatic: true};
}
this.setState({
image: source
});
}
});
}
launchFromLibrary() {
ImagePicker.launchImageLibrary(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
}
else if (response.error) {
console.log('ImagePicker Error: ', response.error);
}
else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
}
else {
// You can display the image using either data...
const source = {uri: 'data:image/jpeg;base64,' + response.data, isStatic: true};
// or a reference to the platform specific asset location
if (Platform.OS === 'ios') {
const source = {uri: response.uri.replace('file://', ''), isStatic: true};
} else {
const source = {uri: response.uri, isStatic: true};
this.state.FileUri = source.uri;
}
this.setState({
image: source
});
}
});
}`
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top GitHub Comments
Yes the first is due to the emulator and here is the onActivityResult in my mainActivity:
Thank you yfuks i solved the problem based on your help and it was due to overriding the onActivityResult.