android - zxing lib does not scan qrcode fast -
i'm using zxing library scan qr codes, find takes lots of time scan code. below can find code i've used implement scanner. dont know whether missing something?
mainactivity.java:
package com.nadhi.qrcodescanner; import android.app.activity; import android.app.alertdialog; import android.content.activitynotfoundexception; import android.content.dialoginterface; import android.content.intent; import android.net.uri; import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.view.view; import android.widget.toast; import com.google.zxing.client.android.captureactivity; public class mainactivity extends appcompatactivity { static final string action_scan = "com.google.zxing.client.android.scan"; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); //set main content layout of activity setcontentview(r.layout.activity_main); } //product qr code mode public void scanqr(view v) { intent intent = new intent(mainactivity.this, captureactivity.class); intent.putextra("scan_mode", "qr_code_mode"); startactivityforresult(intent, 0); try { //start scanning activity com.google.zxing.client.android.scan intent intent intent = new intent(action_scan); intent.putextra("scan_mode", "qr_code_mode"); startactivityforresult(intent, 0); } catch (activitynotfoundexception anfe) { //on catch, show download dialog showdialog(mainactivity.this, "no scanner found", "download scanner code activity?", "yes", "no").show(); } } //alert dialog downloaddialog private static alertdialog showdialog(final activity act, charsequence title, charsequence message, charsequence buttonyes, charsequence buttonno) { alertdialog.builder downloaddialog = new alertdialog.builder(act); downloaddialog.settitle(title); downloaddialog.setmessage(message); downloaddialog.setpositivebutton(buttonyes, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialoginterface, int i) { uri uri = uri.parse("market://search?q=pname:" + "com.google.zxing.client.android"); intent intent = new intent(intent.action_view, uri); try { act.startactivity(intent); } catch (activitynotfoundexception anfe) { } } }); downloaddialog.setnegativebutton(buttonno, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialoginterface, int i) { } }); return downloaddialog.show(); } //on activityresult method public void onactivityresult(int requestcode, int resultcode, intent intent) { if (requestcode == 0) { if (resultcode == result_ok) { //get extras returned intent string contents = intent.getstringextra("scan_result"); string format = intent.getstringextra("scan_result_format"); toast toast = toast.maketext(this, "content:" + contents + " format:" + format, toast.length_long); toast.show(); } } } }
i giving permission in androidmanifest.xml scan qrcode.
androidmanifest.xml:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.nadhi.qrcodescanner" android:versioncode="1" android:versionname="1.0" > <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"/> <!-- unavailable in api 23 --> <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"/> <uses-sdk android:minsdkversion="8" android:targetsdkversion="21" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name=".mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="com.google.zxing.client.android.captureactivity" android:screenorientation="sensorlandscape" android:theme="@style/capturetheme" android:windowsoftinputmode="statealwayshidden"> <intent-filter> <action android:name="com.google.zxing.client.android.scan"/> <category android:name="android.intent.category.default"/> </intent-filter> <!-- allow web apps launch barcode scanner linking http://zxing.appspot.com/scan. --> <intent-filter> <action android:name="android.intent.action.view"/> <category android:name="android.intent.category.default"/> <category android:name="android.intent.category.browsable"/> <data android:scheme="http" android:host="zxing.appspot.com" android:path="/scan"/> </intent-filter> <!-- support google product search url. --> <intent-filter> <action android:name="android.intent.action.view"/> <category android:name="android.intent.category.default"/> <category android:name="android.intent.category.browsable"/> <data android:scheme="http" android:host="www.google.com" android:path="/m/products/scan"/> </intent-filter> <!-- , uk version. --> <intent-filter> <action android:name="android.intent.action.view"/> <category android:name="android.intent.category.default"/> <category android:name="android.intent.category.browsable"/> <data android:scheme="http" android:host="www.google.co.uk" android:path="/m/products/scan"/> </intent-filter> <!-- support zxing://scan/?... iphone app --> <intent-filter> <action android:name="android.intent.action.view"/> <category android:name="android.intent.category.default"/> <category android:name="android.intent.category.browsable"/> <data android:scheme="zxing" android:host="scan" android:path="/"/> </intent-filter> </activity> </application>? </manifest>
Comments
Post a Comment