javascript - How can I get a value on a button click inside a WebView? -


i have native android app goes webview checkout process. implementing appsflyer track revenue through app. how can detect button clicked on page, , item price revenue?

import android.app.activity; import android.app.progressdialog; import android.content.intent; import android.graphics.bitmap; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.util.log; import android.view.motionevent; import android.view.view; import android.webkit.webchromeclient; import android.webkit.webview; import android.webkit.webviewclient; import android.widget.textview;  import com.appsflyer.afinappeventparametername; import com.appsflyer.afinappeventtype; import com.appsflyer.appsflyerlib;  import org.json.jsonexception; import org.json.jsonobject;  import java.text.simpledateformat; import java.util.date; import java.util.hashmap; import java.util.map;  public class eventactivity extends appcompatactivity {      progressdialog pdialog;     boolean redirecting = false;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_event);          string appsflyeruid = appcore.getinstance(getapplicationcontext()).getappsflyeruid();         string idfa = appcore.getinstance(getapplicationcontext()).getmixpaneladvertisingidentifier();          intent intent = getintent();          try {             jsonobject event = new jsonobject(intent.getstringextra("event"));              string eventid = event.getstring("id");             string title = event.getstring("title");             string startsat = event.getstring("starts_at");             string venue = event.getstring("venue");             string city = event.getstring("city");             string state = event.getstring("state");              simpledateformat format = new simpledateformat("yyyy-mm-dd't'hh:mm:ss");             date newdate = format.parse(startsat);              format = new simpledateformat("eeee, mmmm d @ h:mm a");             string date = format.format(newdate);              ((textview)findviewbyid(r.id.event_title)).settext(title);             ((textview)findviewbyid(r.id.event_date)).settext(date);             ((textview)findviewbyid(r.id.event_venue)).settext(venue + " - " + city + ", " + state);              string url = "http://tlapi.ticketliquidator.com/event_map/" + eventid + "?utm_campaign=" + idfa + "&utm_term=" + appsflyeruid;               map<string, object> eventvalue = new hashmap<string, object>();             appsflyerlib.getinstance().trackevent(getapplicationcontext(), "view event " + eventid,eventvalue);               final webview wv = (webview) findviewbyid(r.id.event_webview);             wv.getsettings().setjavascriptenabled(true);             final activity self = this;              wv.setwebviewclient(new webviewclient() {                 public boolean shouldoverrideurlloading(webview view, string url) {                     redirecting = true;                     view.loadurl(url);                     return true;                 }                 public void onpagefinished(webview view, string url) {                     if(redirecting){                         pdialog.dismiss();                     }                 }                 public void onpagestarted(webview view, string url, bitmap favicon) {                     if(redirecting){                         pdialog = new progressdialog(self);                         pdialog.setprogressstyle(progressdialog.style_spinner);                         pdialog.setmessage(" loading...");                         pdialog.setcancelable(true);                         pdialog.show();                     }                  }             });               pdialog = new progressdialog(this);             pdialog.setmessage("getting event...");             pdialog.show();              wv.setwebchromeclient(new webchromeclient() {                 public void onprogresschanged(webview view, int progress) {                      if(progress == 100)                         pdialog.dismiss();                 }             });              wv.loadurl(url);         } catch (exception e) {             e.printstacktrace();         }       } } 

this android class webview. trying pull information web page...

api webview

i need know button clicked in webview, , price beside button. send appsflyer tracking.

you'll have trick java script after loading page you'll have inject javascript loaded webpage this

@override public void onpagefinished(webview view, string url){    // javascript string works fine in scratchpad    string javascript ="javascript:(function() {alert();})()";     webview.loadurl(javascript); } 

so that can inject javascript , find respective dom per requirement , based on can call java method this.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -