android - zxing doesn't handle null properly -
the error message zxing should show if result null doesn't come up. need change? code here:
public void onactivityresult(int requestcode, int resultcode, intent intent) { intentresult scanningresult = intentintegrator.parseactivityresult(requestcode, resultcode, intent); if (scanningresult != null) { //we have result scancontent = scanningresult.getcontents(); scanformat = scanningresult.getformatname(); formattxt.settext("format: " + scanformat); contenttxt.settext("content: " + scancontent); toast.maketext(this, "please click 'update database' after message ends", toast.length_long).show(); } else{ toast.maketext(getapplicationcontext(),"no scan data received. restart scanner", toast.length_short).show(); } }
no matter result, 'please click' toast keeps appearing.
as per answer, have tweaked code following:
// retrieve scan result public void onactivityresult(int requestcode, int resultcode, intent intent) { //string contents = null; //intentresult scanningresult = intentintegrator.parseactivityresult(requestcode, resultcode, intent); super.onactivityresult(requestcode, resultcode, intent); if (requestcode == 0) { //we have result if (resultcode ==result_ok){ scancontent = intent.getstringextra("scan_result"); scanformat = intent.getstringextra("scan_result_format"); formattxt.settext("format: " + scanformat); contenttxt.settext("content: " + scancontent); toast.maketext(this, "please click 'update database' after message ends", toast.length_long).show(); } else if (resultcode == result_canceled) { toast.maketext(getapplicationcontext(),"no scan data received. restart scanner", toast.length_short).show(); } } }
while there don't appear syntax errors, scanning doesn't display output.
you should use onactivityresult
public void onactivityresult(int requestcode, int resultcode, intent data) { string contents = null; super.onactivityresult(requestcode, resultcode, data); if (requestcode == 0) { if (resultcode == result_ok) { contents = data.getstringextra("scan_result"); string format = data.getstringextra("scan_result_format"); //moved here textview tv = (textview) findviewbyid(r.id.scanresult); tv.settext(contents); // handle successful scan } else if (resultcode == result_canceled) { // handle cancel } }