java - How to get the activity result for barcode scanner android? -


how scanned barcode result custom scanner using zxing library ? on activity result not working. scanning part working fine , getting result. not getting data in activity result.

public class scanneractivity extends activity implements zxingscannerview.resulthandler{  resulthandler resulthandler; parameters parameters; private capturemanager capture; private compoundbarcodeview barcodescannerview; private button switchflashlightbutton; private zxingscannerview mscannerview; barcodeview test;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_custom_scanner);      bundle extras = this.getintent().getextras();     resulthandler = (resulthandler) extras.getserializable("result_handler");     parameters = (parameters) extras.getserializable("parameters");      barcodescannerview = (compoundbarcodeview)findviewbyid(r.id.zxing_barcode_scanner);     this.getintent().putextra("result_handle",resulthandler);     capture = new capturemanager(this, barcodescannerview);     capture.initializefromintent(getintent(), savedinstancestate);     capture.decode(); }  @override public void onactivityresult(int requestcode, int resultcode, intent intent) {     log.d("onactivityresult", "onactivityresult: .");     if (resultcode == activity.result_ok) {         intentresult scanresult = intentintegrator.parseactivityresult(requestcode, resultcode, intent);         string re = scanresult.getcontents();         string message = re;         log.d("onactivityresult", "onactivityresult: ."+ re);         result handlerresult = new result(result.status_success, "qrcode", message);         resulthandler.onhandleresult(handlerresult);         this.finish();     }     // else continue other code need in method  }   @override protected void onresume() {     log.d("onresume", "onresume: .");     super.onresume();     capture.onresume(); }  @override protected void onpause() {     log.d("onpause", "onpause: .");     super.onpause();     capture.onpause(); }  @override protected void ondestroy() {     super.ondestroy();     capture.ondestroy(); }   @override protected void onsaveinstancestate(bundle outstate) {     log.d("onsaveinstancestate", "onsaveinstancestate: .");     super.onsaveinstancestate(outstate);     capture.onsaveinstancestate(outstate); } 

}

[ full source code example ]

you have give permission manifesto file:

<uses-permission android:name="android.permission.camera" /> <uses-permission android:name="android.permission.flashlight" /> <uses-permission android:name="android.permission.write_extern al_storage" /> 

and add following code in manifesto application tag:

<activity             android:name=".encode.encodeactivity"             android:label="@string/app_name"             android:statenotneeded="true" >             <intent-filter>                 <action android:name="com.google.zxing.client.android.encode" />                  <category android:name="android.intent.category.default" />             </intent-filter>             <!-- allows handle share button in contacts. -->             <intent-filter>                 <action android:name="android.intent.action.send" />                  <category android:name="android.intent.category.default" />                  <data android:mimetype="text/x-vcard" />             </intent-filter>             <!-- allows handle sharing plain text . -->             <intent-filter>                 <action android:name="android.intent.action.send" />                  <category android:name="android.intent.category.default" />                  <data android:mimetype="text/plain" />             </intent-filter>         </activity>         <activity             android:name="com.google.zxing.client.android.captureactivity"             android:configchanges="orientation|keyboardhidden"             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> 

and onactivityresult() method this:

public void onactivityresult(int requestcode, int resultcode, intent intent) {     super.onactivityresult(requestcode, resultcode, intent);     if (requestcode == 0) {          if (resultcode == result_ok) {             textviewformat.settext(intent.getstringextra("scan_result_format"));             textviewdata.settext(intent.getstringextra("scan_result"));              uri imageuri = intent.getdata();             bitmap bitmap;             try{                 bitmap = mediastore.images.media.getbitmap(this.getcontentresolver(), imageuri);                 scannedbitmap.setimagebitmap(bitmap);             } catch(exception e){                 e.printstacktrace();             }              //toast.maketext(getapplicationcontext(), intent.getstringextra("scan_result_format") + ":" + intent.getstringextra("scan_result"), 5000).show();         } else if (resultcode == result_canceled) {             textviewformat.settext("");             textviewdata.settext("cancelled user");         }      } }   /**  * method used converting bitmatrix bitmap  * @param matrix  * @return bitmap  */ public static bitmap tobitmap(bitmatrix bitmatrix){     int height = bitmatrix.getheight();     int width = bitmatrix.getwidth();     bitmap bmp = bitmap.createbitmap(width, height, bitmap.config.rgb_565);     (int x = 0; x < width; x++){         (int y = 0; y < height; y++){             bmp.setpixel(x, y, bitmatrix.get(x,y) ? color.black : color.white);         }     }     return bmp; } 

see git source code


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -