i know how setting proxy manually , use in webview.
settings -> wireless networks ->mobile networks-> access point names->telkila. enter proxy server address , port (which 80). webview.enableplatformnotifications();
but can set proxy setting code? user didn't have set manually?
thanks
there no legal way change webview proxy settings programmatically. it's possible use java reflection change mproxyhost value android.net.http.requestqueue class. it's private value , there no setters it, reflection seems possible variant. used in project , works. here sample of method:
private boolean setproxyhostfield(httphost proxyserver) { // getting network class networkclass = null; object network = null; try { networkclass = class.forname("android.webkit.network"); field networkfield = networkclass.getdeclaredfield("snetwork"); network = getfieldvaluesafely(networkfield, null); } catch (exception ex) { log.e(proxymanager.class.getname(), "error getting network"); return false; } if (network == null) { log.e(proxymanager.class.getname(), "error getting network : null"); return false; } object requestqueue = null; try { field requestqueuefield = networkclass .getdeclaredfield("mrequestqueue"); requestqueue = getfieldvaluesafely(requestqueuefield, network); } catch (exception ex) { log.e(proxymanager.class.getname(), "error getting field value"); return false; } if (requestqueue == null) { log.e(proxymanager.class.getname(), "request queue null"); return false; } field proxyhostfield = null; try { class requestqueueclass = class.forname("android.net.http.requestqueue"); proxyhostfield = requestqueueclass .getdeclaredfield("mproxyhost"); } catch (exception ex) { log.e(proxymanager.class.getname(), "error getting proxy host field"); return false; } synchronized (synchronizer) { boolean temp = proxyhostfield.isaccessible(); try { proxyhostfield.setaccessible(true); proxyhostfield.set(requestqueue, proxyserver); } catch (exception ex) { log.e(proxymanager.class.getname(), "error setting proxy host"); } { proxyhostfield.setaccessible(temp); } } return true; } private 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; }
Comments
Post a Comment