Zxing 库实现:下面关于在扫描 Activity 后取回结果的部分给出了错误

Zxing library implementation : And the below part on getting back the result after the scanning Activity gives an error

当从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();