phonegap / phonegap-plugin-barcodescanner

cross-platform BarcodeScanner for Cordova / PhoneGap
MIT License
1.27k stars 1.42k forks source link

App crashes when try to open camera #876

Closed martins-a closed 4 years ago

martins-a commented 4 years ago

I installed this plugin on my app

I'm using cordova 8.0.0

When I use the scan method, I got this error (captured using logcat)

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.my.app/com.google.zxing.client.android.CaptureActivity}; have you declared this activity in your AndroidManifest.xml?

What should I do?

martins-a commented 4 years ago

Hi, I found the issue... Your plugin.xml sometimes don't put the these tags on Manifest.xml:

<activity android:clearTaskOnLaunch="true" android:configChanges="orientation|keyboardHidden|screenSize" android:exported="false" android:name="com.google.zxing.client.android.CaptureActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden" /> <activity android:label="Share" android:name="com.google.zxing.client.android.encode.EncodeActivity" />

This is why some users remove android platform and add again and claim that the "problem is solved" - after some "android run" or "android prepare" commands, the error occurs again.

I made a Workaround, placing commands on my config.xml :

 <custom-config-file parent="./application" target="AndroidManifest.xml">
            <activity android:label="Share" android:name="com.google.zxing.client.android.encode.EncodeActivity" />
            <activity android:clearTaskOnLaunch="true" android:configChanges="orientation|keyboardHidden|screenSize" android:exported="false" android:name="com.google.zxing.client.android.CaptureActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden" />
        </custom-config-file>

This tags add the missing activities on application tag at AndroidManifest.xml using this package: https://github.com/dpa99c/cordova-custom-config