gpt4 book ai didi

java - Zxing 库实现 : And the below part on getting back the result after the scanning Activity gives an error

转载 作者:太空狗 更新时间:2023-10-29 13:52:59 25 4
gpt4 key购买 nike

当来自 com.google.zxing.client.android.SCAN 的扫描 Activity 完成时,我想取回结果,并打印扫描的对象,因此我使用了 onActivityResult 方法。但是在 Toast 线上发生错误。

public void onActivityResult(int reqCode, int resCode, Intent intent1) {
if (requestCode == 0) {
if (resCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Toast toast = Toast.makeText("Content:" + contents + " Format:" + format, Toast.LENGTH_LONG);
toast.show();
}
}

}

最佳答案

您需要将上下文传递给 Toast:

Context context = getApplicationContext();
String text = "Content:" + contents + " Format:" + format;
Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG).show();

关于java - Zxing 库实现 : And the below part on getting back the result after the scanning Activity gives an error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43590047/

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