Launching a new Android activity via Javascript in a Webview -


i have android test app , trying call function javacriptinterface class. webview plays video , when ends calls js method should call android method launch new activity.

that doesn't seem happening @ all, when video done it's webview reloads , plays video again.

is possible launch activity this? can provideo sample code in 45 minutes.

the videoactivity.java

public class mainactivity extends activity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     getwindow().requestfeature(window.feature_action_bar);     getactionbar().hide();     this.setrequestedorientation(activityinfo.screen_orientation_landscape);     setcontentview(r.layout.activity_main);       try     {         webview mywebview = (webview) findviewbyid(r.id.webview);         mywebview.setwebchromeclient(new webchromeclient() {         });         websettings websettings = mywebview.getsettings();         websettings.setjavascriptenabled(true);          intent = new intent("com.example.myapplication.blankactivity");         mywebview.addjavascriptinterface(new javascriptinterface(this,i), "android");         mywebview.loadurl("url");     }     catch(exception e) {         string msg = e.getmessage();         string trace = e.getstacktrace().tostring();     }   }  public class javascriptinterface {     context mcontext;     intent i;      /** instantiate interface , set context */     javascriptinterface(context c, intent i) {         mcontext = c;         this.i = i;     }      /** show toast web page */     public void oncomplete(string toast) {         startactivity(i);     } }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.main, menu);     return true; } 

}

blankactivity.java

public class blankactivity extends activity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_blank); }   @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.blank, menu);     return true; } 

}

here's javascript code on page webview runs when video done.

function oncomplete() {     android.oncomplete(); } 

as


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -