qr code - Android Zxing camera not working when backpress -
i'm facing issue on zxing qr code scanner. issue when press button webpage or new activity, scanner stop working , not able scan anything. can tell me mistakes? :x in advance.
import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.view.view; import android.widget.button; import android.widget.toast; import android.util.patterns; import android.content.intent; import com.google.zxing.result; import android.net.uri; import me.dm7.barcodescanner.zxing.zxingscannerview; public class scanneractivity extends appcompatactivity implements zxingscannerview.resulthandler { private zxingscannerview zxingscannerview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_scanner); } public void scan(view view) { zxingscannerview = new zxingscannerview(getapplicationcontext()); setcontentview(zxingscannerview); zxingscannerview.setresulthandler(this); zxingscannerview.startcamera(); } public void onpause() { super.onpause(); zxingscannerview.stopcamera(); } @override public void handleresult(result result) { toast.maketext(getapplicationcontext(), result.gettext(), toast.length_short).show(); zxingscannerview.resumecamerapreview(this); if(patterns.web_url.matcher(result.gettext()).matches()) { // open url intent browserintent = new intent(intent.action_view, uri.parse(result.gettext())); startactivity(browserintent); } if(result.gettext().equals("welcome booth a")) { // open nextactivity intent quiz1 = new intent(this, quizactivity.class); startactivity(quiz1); } }
you need override onbackpressed
method in scanneractivity
. can like
@override public void onbackpressed() { //do }
the default method call destroys current fragment or activity. goes through onpause
, in stopped camera doing zxingscannerview.stopcamera();
.
Comments
Post a Comment