Comments (6)
@aseemnishad @oferRounds Is it working? I am getting many erros!! Can you share your code?
from react-native-android-scanner.
@oferRounds sorry, I didn't get much from the report, i can help you to debug, can you please share the code?
from react-native-android-scanner.
Hi @aseemnishad
Thanks fist of all!
I found out what’s the causing the issue: it’s the fact that FileProvider.getUriForFile
is passing an authority which is specific for the scanlibrary, and on my case, it conflicts with other dependency, which also uses one.
I think the best would be to refactor the openCamera
method like this, to pass the applicationContext.getPackageName() + ".provider"
as the `authority:
public void openCamera() {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File file = createImageFile();
boolean isDirectoryCreated = file.getParentFile().mkdirs();
Log.d("", "openCamera: isDirectoryCreated: " + isDirectoryCreated);
Uri tempFileUri;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
tempFileUri = Uri.fromFile(file);
} else {
Context applicationContext = getActivity().getApplicationContext();
tempFileUri = FileProvider.getUriForFile(applicationContext,
applicationContext.getPackageName() + ".provider",
file);
}
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempFileUri);
startActivityForResult(cameraIntent, ScanConstants.START_CAMERA_REQUEST_CODE);
}
from react-native-android-scanner.
@oferRounds Glad you found the solution and thank you for the suggestion, i would change it.
from react-native-android-scanner.
awesome, thank you once again!
from react-native-android-scanner.
@oferRounds I'm also having same problem. when opening camera , the app was crashed. ie: "Unfortumately app was stopped ".
any idea about this?
This is my code:
import React, {Component} from 'react';
import {
Platform,
StyleSheet,
Text,
View,
DeviceEventEmitter,
ToastAndroid,
TouchableOpacity,
Image
} from 'react-native';
import RNAndroidScanner from 'react-native-android-scanner';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
imageUri: null
};
}
componentWillMount = () => {
ToastAndroid.show('Listening for SCANNED_RESULT', ToastAndroid.SHORT);
DeviceEventEmitter.addListener(RNAndroidScanner.SCANNED_RESULT, this.onResult);
}
onScan(preference = 2){
RNAndroidScanner.startScan(preference);
}
onResult = (image) => {
ToastAndroid.show('onResult completion callback:', ToastAndroid.SHORT);
this.setState({imageUri: image.uri})
}
render() {
return (
React Native Android Scanner Demo
<TouchableOpacity onPress={() => this.onScan()}>
Start Scan
<Image
style={styles.image}
source={{
uri: this.state.imageUri
}}
resizeMode="contain"/>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF'
},
imageContainer: {
flex: 1,
justifyContent: 'flex-start',
alignItems: 'center'
},
image: {
width: 150,
height: 150,
},
buttonContainer: {
flex: 1,
justifyContent: 'center',
marginTop: 50,
alignItems: 'center'
},
welcome: {
fontSize: 15,
textAlign: 'center',
margin: 10
},
scanButton: {
fontSize: 17,
textAlign: 'center',
color: '#333333',
marginBottom: 30
}
});
from react-native-android-scanner.
Related Issues (10)
- Attribute application@allowBackup is also present at [:scanlibrary] HOT 3
- error: cannot find symbol import android.support.v7.app.ActionBarActivity; HOT 7
- Error calling RCTEventEmitter.receiverTouches HOT 2
- Build fails HOT 3
- Update The Installation Steps of Android
- Can We Use Properties to Change Orientation of Image?
- Image Orientation issue on Samsung Devices HOT 1
- not able to install
- Crash when using with 64 bit HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-android-scanner.