java - Using Proxy Behind WebView -
its week search way make webview works proxy (not using wifi, mobile ddata). didnt found solution yet. can give me work it?
i try there's in (maybe not all, if have way please share it)
take peek @ code
public class webviewactivity extends activity { static webview web; string proxy_ip = "202.58.124.34"; int proxy_port = 8989; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.web_view); web = (webview) findviewbyid(r.id.webview1); web.setwebviewclient(new mywebviewclient("username","password")); web.getsettings().setjavascriptenabled(true); web.getsettings().setjavascriptcanopenwindowsautomatically(true); web.getsettings().setallowcontentaccess(true); web.getsettings().setappcacheenabled(true); system.getproperties().put("proxyset", "true"); system.getproperties().put(proxy_ip, "202.58.124.34"); system.getproperties().put(proxy_port, "8989"); authenticator authenticator = new authenticator() { public passwordauthentication getpasswordauthentication() { return (new passwordauthentication ("username","password".tochararray())); } }; authenticator.setdefault(authenticator); web.sethttpauthusernamepassword("http://202.58.124.34", "", "username", "password"); web.loadurl("url"); } public static boolean setproxyicsplus(webview webview, string host, int port, string exclusionlist) { log.d("", "setting proxy >= 4.1 api."); try { class jwcjb = class.forname("android.webkit.jwebcorejavabridge"); class params[] = new class[1]; params[0] = class.forname("android.net.proxyproperties"); method updateproxyinstance = jwcjb.getdeclaredmethod("updateproxy", params); class wv = class.forname("android.webkit.webview"); field mwebviewcorefield = wv.getdeclaredfield("mwebviewcore"); object mwebviewcorefieldintance = getfieldvaluesafely(mwebviewcorefield, web); class wvc = class.forname("android.webkit.webviewcore"); field mbrowserframefield = wvc.getdeclaredfield("mbrowserframe"); object mbrowserframe = getfieldvaluesafely(mbrowserframefield, mwebviewcorefieldintance); class bf = class.forname("android.webkit.browserframe"); field sjavabridgefield = bf.getdeclaredfield("sjavabridge"); object sjavabridge = getfieldvaluesafely(sjavabridgefield, mbrowserframe); class ppclass = class.forname("android.net.proxyproperties"); class pparams[] = new class[3]; pparams[0] = string.class; pparams[1] = int.class; pparams[2] = string.class; constructor ppcont = ppclass.getconstructor(pparams); updateproxyinstance.invoke(sjavabridge, ppcont.newinstance("202.58.124.34", 8989, null)); } catch (exception ex) { log.e("","setting proxy >= 4.1 api failed error: " + ex.getmessage()); return false; } log.d("", "setting proxy >= 4.1 api successful!"); return true; } private static object getfieldvaluesafely(field field, object classinstance) throws illegalargumentexception, illegalaccessexception { boolean oldaccessiblevalue = field.isaccessible(); field.setaccessible(true); object result = field.get(classinstance); field.setaccessible(oldaccessiblevalue); return result; } public void loadurl(webview view, string url, string proxyusername, string proxypassword){ usernamepasswordcredentials creds= new usernamepasswordcredentials("username", "password"); header credheader = basicscheme.authenticate(creds, "utf-8", true); map<string, string> header = new hashmap<string, string>(); header.put(credheader.getname(), credheader.getvalue()); view.loadurl(url, header); }
i try using public boolean ics, using try , catch method. isnt't showing result (or i'm doing wrong?). please if have way that's work using proxy in webview show way.
thanks.
note: i'm running using mobile data. not wifi. setting mobile data.
Comments
Post a Comment