Code Monkey home page Code Monkey logo

Comments (6)

SwagatRanjit84 avatar SwagatRanjit84 commented on July 1, 2024 1

@aseemnishad @oferRounds Is it working? I am getting many erros!! Can you share your code?

from react-native-android-scanner.

aseemnishad avatar aseemnishad commented on July 1, 2024

@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.

oferRounds avatar oferRounds commented on July 1, 2024

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.

aseemnishad avatar aseemnishad commented on July 1, 2024

@oferRounds Glad you found the solution and thank you for the suggestion, i would change it.

from react-native-android-scanner.

oferRounds avatar oferRounds commented on July 1, 2024

awesome, thank you once again!

from react-native-android-scanner.

ElangoPrince avatar ElangoPrince commented on July 1, 2024

@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
}
});

Error Image:
Screenshot_20190312-170959

from react-native-android-scanner.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.