Zxing library implementation: and the bottom part for getting the result after scanning.
When the scan operation from com.google.zxing.client.android.SCAN finishes, I want to return the result and print the scanned object, so I used the onActivityResult method. But the error occurs on the Toast line.
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();
}
}
}
+3
Achala Yasas Piyarathna
source
to share
1 answer
You need to pass the Toast context like:
Context context = getApplicationContext();
String text = "Content:" + contents + " Format:" + format;
Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG).show();
+1
Sanjog shrestha
source
to share