Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Proxy Behind WebView
    primarykey
    data
    text
    <p>its already a week that i search for the way to make webview works with proxy (not using wifi, just mobile ddata). i didnt found any solution yet. can someone give me something to work with it? </p> <p>i already try all there's that in the SO (maybe not all, if someone have a way please share it)</p> <p>take a peek at my code </p> <pre><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 with &gt;= 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 with &gt;= 4.1 API failed with error: " + ex.getMessage()); return false; } Log.d("", "Setting proxy with &gt;= 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&lt;String, String&gt; header = new HashMap&lt;String, String&gt;(); header.put(credHeader.getName(), credHeader.getValue()); view.loadUrl(url, header); } </code></pre> <p>i already try using the public boolean ICS, using try and catch method. all isnt't showing any result (or i'm doing it wrong?). So please if someone have a way that's work using proxy in webview to show it the way.</p> <p>thanks.</p> <p>Note: i'm running using mobile data. not Wifi. so the setting will be just for mobile data.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload