扫描条形码后,我无法让zxing做任何事情。我用zxing打电话给zxing:
IntentIntegrator.initiateScan(MainActivity.this);
我的onActivityResult看起来像这样
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");
if (format == "PRODUCT_CODE"){
//If the barcode scanned is of the correct type then pass the barcode into the search method to get the product details
Toast.makeText(getApplicationContext(),"You scanned " + contents, 3).show();
}
else{
//If the barcode is not of the correct type then display a notification
Toast.makeText(getApplicationContext(),"You didn't scan a product code", 3).show();
}
} else if (resultCode == RESULT_CANCELED) {
//If the scan is cancelled then display a notification
Toast.makeText(getApplicationContext(),"You cancelled the input", 3).show();
}
}
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");
if (format == "PRODUCT_CODE"){
//If the barcode scanned is of the correct type then pass the barcode into the search method to get the product details
Toast.makeText(getApplicationContext(),"You scanned " + contents, 3).show();
}
else{
//If the barcode is not of the correct type then display a notification
Toast.makeText(getApplicationContext(),"You didn't scan a product code", 3).show();
}
} else if (resultCode == RESULT_CANCELED) {
//If the scan is cancelled then display a notification
Toast.makeText(getApplicationContext(),"You cancelled the input", 3).show();
}
}
但每当我退出zxing时,都不会显示任何内容。我尝试使用示例in the zxing wiki 但每当我尝试用MainActivity或MainActivity替换你的活动时,我都会收到错误(我被告知MainActivity无法解析为字符串,并且使用MainActivity.this构造函数IntentIntegrator(MainActivity)未定义)。
基本上我不知道我在做什么,为什么它不起作用。任何帮助将不胜感激。
答案 0 :(得分:1)
问题与您的其他问题完全相同。您无法将字符串与==
进行比较,但必须使用equals()
。