
这是我的代码对我不起作用
public voID onClick(VIEw v) { Intent intent = new Intent(); intent.putExtra("com.Google.zxing.clIEnt.androID.SCAN.SCAN_MODE", "QR_CODE_MODE"); startActivityForResult(intent, 0); }public voID onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == 0) { if (resultCode == RESulT_OK) { String contents = intent.getStringExtra("SCAN_RESulT"); String format = intent.getStringExtra("SCAN_RESulT_FORMAT"); Toast.makeText(getApplicationContext(),"Contents"+contents+"Format"+format,Toast.LENGTH_LONG).show(); tv.setText(contents+""+format); // Handle successful scan } else if (resultCode == RESulT_CANCELED) { // Handle cancel } }}startActivityForResult(intent,0)中的错误;我不知道如何解决此错误,请帮我
解决方法:
您也可以通过扩展CaptureActivity来完成.
public voID onClick(VIEw v) { Intent intent=new Intent(A.this,ScannerActivity.class); startActivity(intent); }ScannerActivity:
public class ScannerActivity extends CaptureActivity {/** The barcode format. */String barcodeFormat;/** * Called when the activity is first created. * * @param savedInstanceState * the saved instance state */@OverrIDepublic voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.barcode_scan);}/* * (non-Javadoc) * * @see * com.Google.zxing.clIEnt.androID.CaptureActivity#handleDecode(com.Google * .zxing.Result, androID.graphics.Bitmap) */@OverrIDepublic voID handleDecode(Result rawResult, Bitmap barcode) { String barcodeType = rawResult.getbarcodeFormat().toString(); String productID = rawResult.getText(); Toast.makeText(getApplicationContext(),"Contents"+productID +"Format"+barcodeType ,Toast.LENGTH_LONG).show(); //handle intent by sending product ID as your wish...}}
barcode_scan.xml :(不要忘了包含capture.xml)
<?xml version="1.0" enCoding="utf-8"?> <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:orIEntation="vertical" > <include layout="@layout/capture"/> </linearLayout> 总结 以上是内存溢出为你收集整理的java-在Android应用中使用zxing扫描条形码阅读器数据全部内容,希望文章能够帮你解决java-在Android应用中使用zxing扫描条形码阅读器数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)