I added this plugin to my cordova/phonegap project: phonegap-plugin-barcodescanner
.
Sometimes it works, but after some tries it starts to crash the app.
I used logcat to get the error, and this is what i found:
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?
I tried to add this activity to my config.xml using this:
<activity android:configChanges="orientation|keyboardHidden" android:name="com.google.zxing.client.android.CaptureActivity" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
But it get even worse, the app crashes after starting.
Any ideas?
I found the issue... this package 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