android - how could I refresh a webview? -
so made website turned mobile app using webview. when first time install apk, work problem after that, web static or it's not loaded anymore.
it open same content first time install though change whole website. don't know if problem webview or android.
i try made auto refresh/autoreload function in php work in mobile browser , didn't work in app... know solution?
since i'm newbie in android developping i'll put whole code of main activity
public class mainactivity extends appcompatactivity implements navigationview.onnavigationitemselectedlistener { //initializing webview private webview mwebview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout); actionbardrawertoggle toggle = new actionbardrawertoggle( this, drawer, toolbar, r.string.navigation_drawer_open, r.string.navigation_drawer_close); drawer.setdrawerlistener(toggle); toggle.syncstate(); navigationview navigationview = (navigationview) findviewbyid(r.id.nav_view); navigationview.setnavigationitemselectedlistener(this); //webview mwebview = (webview) findviewbyid(r.id.mywebview); websettings websettings = mwebview.getsettings(); websettings.setjavascriptenabled(true); //improve webview performance mwebview.getsettings().setrenderpriority(websettings.renderpriority.high); mwebview.getsettings().setcachemode(websettings.load_cache_else_network); mwebview.getsettings().setappcacheenabled(true); mwebview.setscrollbarstyle(view.scrollbars_inside_overlay); websettings.setdomstorageenabled(true); websettings.setlayoutalgorithm(websettings.layoutalgorithm.narrow_columns); websettings.setusewideviewport(true); websettings.setsavepassword(true); websettings.setsaveformdata(true); websettings.setenablesmoothtransition(true); mwebview.loadurl("http://192.168.94.2/autorefresh/"); //force links open in webview mwebview.setwebviewclient(new mywebviewclient()); } @override public void onbackpressed() { drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout); if (drawer.isdraweropen(gravitycompat.start)) { drawer.closedrawer(gravitycompat.start); } else { super.onbackpressed(); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); return super.onoptionsitemselected(item); } @suppresswarnings("statementwithemptybody") @override public boolean onnavigationitemselected(menuitem item) { // handle navigation view item clicks here. int id = item.getitemid(); if (id == r.id.nav_home) { mwebview.loadurl("http://192.168.94.2/ee1/"); } if (id == r.id.nav_kolam) { mwebview.loadurl("http://192.168.94.2/ee1/listkolam.php"); } if (id == r.id.nav_pantai) { mwebview.loadurl("http://192.168.94.2/ee1/listpantai.php"); } if (id == r.id.nav_transaksi) { system.exit(0); } if (id == r.id.nav_about) { system.exit(0); } if (id == r.id.nav_keluar) { system.exit(0); } drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout); drawer.closedrawer(gravitycompat.start); return true; } //bikin progress dialog private class mywebviewclient extends webviewclient { //progressdialogue @override public boolean shouldoverrideurlloading(webview view, string url) { if (uri.parse(url).gethost().equals("192.168.94.2")) { //open url contents in webview return false; } else { //here open external links in external browser or app intent intent = new intent(intent.action_view, uri.parse(url)); startactivity(intent); return true; } } progressdialog pd = null; @override public void onpagestarted(webview view, string url, bitmap favicon) { pd=new progressdialog(mainactivity.this); pd.settitle("mohon tunggu sebentar"); pd.setmessage("website loading.."); pd.show(); super.onpagestarted(view, url, favicon); } @override public void onpagefinished(webview view, string url) { pd.dismiss(); super.onpagefinished(view, url); } } //bikin tombol halaman @override public boolean onkeydown(int keycode, keyevent event) { if (event.getaction() == keyevent.action_down) { switch (keycode) { case keyevent.keycode_back: if (mwebview.cangoback()) { mwebview.goback(); } else { finish(); } return true; } } return super.onkeydown(keycode, event); }}
i'm using native php
webview.loadurl("javascript:window.location.reload(true)");
this may reload webview. thanks
Comments
Post a Comment