gpt4 book ai didi

android - zxing 条码扫描器结果为空

转载 作者:行者123 更新时间:2023-11-29 18:04:19 25 4
gpt4 key购买 nike

我遵循了 this 的指南页面,我的 Intent 被激发了。它还找到了条形码。然而当

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {

showMessage("result", scanResult.toString());

}
// else continue with any other code you need in the method

}

到达对话框(showMessage 函数基本上只是创建带有标题和文本的对话框)显示以下文本:

Format: null Contents: null Raw bytes: (0bytes) Orientation: null EC level: null

我是否遗漏了某些部分,或者只是条形码的问题?我已经尝试了所有带有条形码的产品,但没有改变。

最佳答案

我的项目曾经做过类似的事情:

public class MenuScreen extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_screen);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_menu_screen, menu);
return true;
}

public void onScanCodeClick(View view) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
try {
startActivityForResult(intent, 0);
} catch (ActivityNotFoundException aex) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("No Application Found");
builder.setMessage("We could not find an application to scan QR CODES."
+ " Would you like to download one from Android Market?");
builder.setPositiveButton("Yes, Please",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent marketIntent = new Intent(Intent.ACTION_VIEW);
marketIntent.setData(Uri
.parse("market://details?id=com.google.zxing.client.android"));
startActivity(marketIntent);
}
});
builder.setNegativeButton("No, Thanks", null);
builder.create().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");

// Handle successful scan

Intent intent2 = new Intent();
intent2.setClass(this, MenuCodeSuccess.class);
intent2.putExtra("qrDetails", contents);
startActivity(intent2);

} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}

}

onScanCodeClick 只是按钮的 onClickListener。您当然可以初始化您的按钮并改用此代码。

这是一个 xml 布局:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2" >

<Button
android:id="@+id/menuScreen_SCANCODE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onScanCodeClick"
android:text="@string/scanButton" />

</TableLayout>

请不要关心布局的样式,你需要的只是在java类中。 :) 但它应该可以正常工作。

关于android - zxing 条码扫描器结果为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14155778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com