javascript - Enable to Get Product Information from any shopping URL on webview android -


i having 1 activity, in web view available , url web view shopping url, when url loads in webview , item select add cart or buy information of product fetch , alertdialog shown above web view.

can guide me same, not able find should use or implement making work need? appreciated. in advance...

here code i've tried fetch product data before asked question.

public class webstoreactivity extends appcompatactivity { webview webview;     string adidas_tag = "product";     string nike_tag = "ch4_cartitem";     string zalando_tag = "z-coast-fjord_article";     string digitec_tag = "item-description";      string adidas_shoppingcart_url = "https://www.adidas.ch/on/demandware.store/sites-adidas-ch-site/de_ch/cart-show";     string nike_shoppingcart_url = "https://secure-store.nike.com/ch/checkout/html/cart.jsp?";     string zalando_shoppingcart_url = "https://www.zalando_tag.ch/cart/";     string digitec_shoppingcart_url = "https://www.digitec.ch/";      private string[] shoppingcartitems;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          setcontentview(r.layout.activity_web_store);         // makes progress bar visible         webview = (webview) findviewbyid(r.id.webview);         webview.getsettings().setdomstorageenabled(true);         webview.addjavascriptinterface(new myjavascriptinterface(this), "shoppingcartanalyser");         webview.getsettings().setjavascriptenabled(true);         swiperefreshlayout refreshlayout = (swiperefreshlayout) findviewbyid(r.id.refresh_web_view_swipe_layout);         refreshlayout.setonrefreshlistener(new swiperefreshlayout.onrefreshlistener() {             @override             public void onrefresh() {                webview.setwebviewclient(new hellowebviewclient());                 webview.loadurl(nike_shoppingcart_url);             }         });         webview.setwebviewclient(new hellowebviewclient());         webview.loadurl(nike_shoppingcart_url);     }       private class hellowebviewclient extends webviewclient {         @override         public void onpagestarted(webview view, string url, bitmap favicon) {             super.onpagestarted(view, url, favicon);             progressbar bar = (progressbar) findviewbyid(r.id.loading_progress_bar);             swiperefreshlayout refreshlayout = (swiperefreshlayout) findviewbyid(r.id.refresh_web_view_swipe_layout);             refreshlayout.setrefreshing(true);             if (bar.getvisibility() == view.gone)                 bar.setvisibility(view.visible);         }          @override         public void onpagefinished(webview view, string url) {             progressbar bar = (progressbar) findviewbyid(r.id.loading_progress_bar);             swiperefreshlayout refreshlayout = (swiperefreshlayout) findviewbyid(r.id.refresh_web_view_swipe_layout);             refreshlayout.setrefreshing(false);             if (bar.getvisibility() == view.visible)                 bar.setvisibility(view.gone);             loadevent(clicklistener());         }          private void loadevent(string javascript) {             webview.loadurl("javascript:" + javascript);         }          private string clicklistener() {             return getproducts() + "for(var = 0; < products.length; i++){\n" +                     "\tconsole.log(products[i].innertext); shoppingcartanalyser.boundmethod(products[i].innertext,i,products.length); \n" +                     "}";         }          private string getproducts() {             return "var products = document.getelementsbyclassname('" + nike_tag + "'); console.log(products.length + ' products');\n";         }      }      private void displayitems() {         (string shoppingcartitem : shoppingcartitems) {             log.d("shoppingcart", cleanstring(shoppingcartitem));         }     }      private string cleanstring(string shoppingcartitem) {         shoppingcartitem = shoppingcartitem.replace("Ändern", "");         shoppingcartitem = shoppingcartitem.replace("entfernen", "");         shoppingcartitem = shoppingcartitem.replace("bearbeiten", "");         shoppingcartitem = shoppingcartitem.replace("löschen", "");         shoppingcartitem = shoppingcartitem.replace("icon-cart-minus", "");         shoppingcartitem = shoppingcartitem.replace("icon-cart-plus", "");         shoppingcartitem = shoppingcartitem.replace("service + zubehör", "");         shoppingcartitem = shoppingcartitem.replaceall("(?m)^[ \t]*\r?\n", "");         return shoppingcartitem;     }        private class myjavascriptinterface {          private context ctx;          myjavascriptinterface(context ctx) {             this.ctx = ctx;         }          @javascriptinterface         public void boundmethod(string decodedshoppingcart, int i, int size) {             if (i == 0) {                 shoppingcartitems = new string[size];             }             shoppingcartitems[i] = decodedshoppingcart;             if (i == size - 1) {                 displayitems();             }         }     } } 


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -