本文介绍了扫描Android应用使用zxing酒吧code读卡器数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的code不为我工作
this is my code doesn't work for me
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(意向,0);我不知道我怎么能解决这个错误plz帮助我
error in startActivityForResult(intent, 0); i don't know how can i solved this error plz help me
推荐答案
您还可以通过扩展CaptureActivity做的。
You can also do by extending CaptureActivity.
public void onClick(View v) {
Intent intent=new Intent(A.this,ScannerActivity.class);
startActivity(intent);
}
ScannerActivity:
ScannerActivity:
public class ScannerActivity extends CaptureActivity {
/** The barcode format. */
String barcodeFormat;
/**
* Called when the activity is first created.
*
* @param savedInstanceState
* the saved instance state
*/
@Override
public 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)
*/
@Override
public 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...
}
}
酒吧code_scan.xml:(不要忘了包括capture.xml)
barcode_scan.xml:(don't forget to include 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>
这篇关于扫描Android应用使用zxing酒吧code读卡器数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!