java - Barcode Scanner (ZXing) crashing -
first off want tell have done can. followed 10 tutorials on internet , 10 threads on stacked. still no success.
i know guys recommend using scanning via intent,but in case not option , need have native in app.
i have downloaded zxing library (2.1) , followed this tutorial
when run code on galaxy s3 or galaxy tab 10.1 debug, program crashes, after freezing 20 seconds, when click button should start intent result: com.google.zxing.client.android.scan
or com.google.zxing.client.android.captureactivity
.
note have copied resources barcode scanner app beep sound, xml files , other.
my code below:
mainactivity.java
package com.example.philipscan; import android.os.bundle; import android.app.activity; import android.content.intent; import android.util.log; import android.view.menu; import android.view.view; public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } public void scannow(view view) { log.e("test", "button works!"); intent intent = new intent("com.google.zxing.client.android.captureactivity"); startactivityforresult(intent, 3); } public void onactivityresult(int requestcode, int resultcode, intent intent) { log.e("xzing", "back"); if (requestcode == 3) { if (resultcode == result_ok) { string contents = intent.getstringextra("scan_result"); string format = intent.getstringextra("scan_result_format"); log.e("xzing", "contents: "+contents+" format: "+format); // handle successful scan } else if (resultcode == result_canceled) { // handle cancel log.e("xzing", "cancelled"); } } } }
android manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.philipscan" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" android:targetsdkversion="17" /> <uses-feature android:name="android.hardware.camera"/> <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/> <uses-feature android:name="android.hardware.camera.flash" android:required="false"/> <uses-feature android:name="android.hardware.screen.landscape"/> <uses-feature android:name="android.hardware.wifi" android:required="false"/> <uses-feature android:name="android.hardware.touchscreen" android:required="false"/> <uses-permission android:name="android.permission.camera"/> <uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.vibrate"/> <uses-permission android:name="android.permission.flashlight"/> <uses-permission android:name="android.permission.read_contacts"/> <uses-permission android:name="com.android.browser.permission.read_history_bookmarks"/> <uses-permission android:name="android.permission.write_external_storage"/> <uses-permission android:name="android.permission.change_wifi_state"/> <uses-permission android:name="android.permission.access_wifi_state"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.example.philipscan.mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> <intent-filter> <action android:name="com.google.zxing.client.android.scan"/> <category android:name="android.intent.category.default" /> </intent-filter> </activity> <activity android:name="com.google.zxing.client.android.captureactivity" android:label="@string/app_name" > <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> </application> </manifest>
my src folder
i'm thankful can get.
try create intent
way
intent scanintent = new intent("com.google.zxing.client.android.scan"); scanintent.putextra("scan_mode", "one_d_mode");
then startactivityforresult() usual. one_d_mode mode scan 1d barcodes code39.