java - Zxing barcode scanner implementation intent -


i've been looking everywhere regarding implementing barcode scanner application/ i've included code which'll enable user scan if barcode scanner installed need prompt user download application if isn't installed? followed example me far.

here code

    package com.example.zxingscan;  import android.os.bundle; import android.app.activity; import android.content.intent; import android.view.view; import android.view.view.onclicklistener; import android.widget.textview;  public class main extends activity {   @override   public void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);      setcontentview(r.layout.activity_main);      handleclick hc = new handleclick();      findviewbyid(r.id.butqr).setonclicklistener(hc);    }    private class handleclick implements onclicklistener{      public void onclick(view arg0) {        intent intent = new intent("com.google.zxing.client.android.scan");        switch(arg0.getid()){          case r.id.butqr:            intent.putextra("scan_mode", "qr_code_mode");          break;         }       startactivityforresult(intent, 0);    //barcode scanner scan     }   }   public void onactivityresult(int requestcode, int resultcode, intent intent) {     if (requestcode == 0) {       textview tvstatus=(textview)findviewbyid(r.id.tvstatus);       textview tvresult=(textview)findviewbyid(r.id.tvresult);       if (resultcode == result_ok) {         tvstatus.settext(intent.getstringextra("scan_result_format"));         tvresult.settext(intent.getstringextra("scan_result"));       } else if (resultcode == result_canceled) {         tvstatus.settext("press button start scan.");         tvresult.settext("scan cancelled.");       }     }   } } 

first of create dialog briefly explains situation , suggests install free zxing scanner app google play. add cancel , install button. i'm not going explain how here. take @ alertdialog.builder tutorial example.

upon user confirmation (install button click) need start following intent:

startactivity(new intent(intent.action_view,     uri.parse("market://details?id=com.google.zxing.client.android"))); 

market protocol uris can used open app detail pages google play market. see this android documentation page more information.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -