Android Context Set setWebkitProxyICS(Context ctx, String host, int port)

Here you can find the source of setWebkitProxyICS(Context ctx, String host, int port)

Description

set Webkit Proxy ICS

Declaration

private static boolean setWebkitProxyICS(Context ctx, String host,
            int port) throws Exception 

Method Source Code

//package com.java2s;

import java.lang.reflect.Constructor;

import java.lang.reflect.Method;

import android.content.Context;

import android.util.Log;

public class Main {
    private static boolean setWebkitProxyICS(Context ctx, String host,
            int port) throws Exception {

        // PSIPHON: added support for Android 4.x WebView proxy
        try {/*www  . ja  va2 s .  c om*/
            Class webViewCoreClass = Class
                    .forName("android.webkit.WebViewCore");

            Class proxyPropertiesClass = Class
                    .forName("android.net.ProxyProperties");
            if (webViewCoreClass != null && proxyPropertiesClass != null) {
                Method m = webViewCoreClass.getDeclaredMethod(
                        "sendStaticMessage", Integer.TYPE, Object.class);
                Constructor c = proxyPropertiesClass.getConstructor(
                        String.class, Integer.TYPE, String.class);

                if (m != null && c != null) {
                    m.setAccessible(true);
                    c.setAccessible(true);
                    Object properties = c.newInstance(host, port, null);

                    // android.webkit.WebViewCore.EventHub.PROXY_CHANGED = 193;
                    m.invoke(null, 193, properties);
                    return true;
                } else
                    return false;
            }
        } catch (Exception e) {
            Log.e("ProxySettings",
                    "Exception setting WebKit proxy through android.net.ProxyProperties: "
                            + e.toString());
        } catch (Error e) {
            Log.e("ProxySettings",
                    "Exception setting WebKit proxy through android.webkit.Network: "
                            + e.toString());
        }

        return false;

    }
}

Related

  1. setLanguage(Context context, String language)
  2. setProxy(Context ctx)
  3. setProxy(Context ctx, String host, int port)
  4. setRevokedPermissions(String packageName, String[] permissions, Context ctx)
  5. setWebkitProxyGingerbread(Context ctx, String host, int port)
  6. setWelcomeShown(final Context ctx)