android - I can't use Intent at Activity -
when click marker on google map, want enter activity, when got result javascript, can't intent
websettings websetting = webview.getsettings(); websetting.setjavascriptenabled(true); websetting.setdisplayzoomcontrols(true); websetting.setsupportzoom(true); websetting.setbuiltinzoomcontrols(true); webview.addjavascriptinterface(new javascriptinterfacetest(this), "android");
and javascriptinterfacetest()
:
public class javascriptinterfacetest { context mcontext; /** instantiate interface , set context */ javascriptinterfacetest(context c) { mcontext = c; } /** show toast web page */ @javascriptinterface public void responseresult(string result){ log.e("jscallback","drink"); intent mainintent = new intent(mainactivity.this, test.class); startactivity(mainintent); } @javascriptinterface private void startactivity(intent mainintent) { // todo auto-generated method stub } }
html:
drinkmarker = new google.maps.marker({ position: {lat: 25.079734,lng: 121.569519}, map: map, }); drinkmarker.addlistener('click',function(){ android.responseresult("drink"); });
pass current context instead of mainactivity
public class javascriptinterfacetest { context mcontext; /** instantiate interface , set context */ javascriptinterfacetest(context c) { mcontext = c; } /** show toast web page */ @javascriptinterface public void responseresult(string result){ log.e("jscallback","drink"); intent mainintent = new intent(mcontext, test.class); mcontext.startactivity(mainintent); } @javascriptinterface private void startactivity(intent mainintent) { // todo auto-generated method stub } }
Comments
Post a Comment