2015년 6월 28일 일요일

android proxy setting check

안드로이드 wifi proxy 체크

http://stackoverflow.com/questions/10811698/getting-wifi-proxy-settings-in-android

public static String[] getUserProxy(Context context)
{
    Method method = null;
    try
    {
      method = ConnectivityManager.class.getMethod("getProxy");
    }
    catch (NoSuchMethodException e)
    {
      // Normal situation for pre-ICS devices
      return null;
    }
    catch (Exception e)
    {
      return null;
    }

    try
    {
      ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
      Object pp = method.invoke(connectivityManager);
      if (pp == null)
        return null;

      return getUserProxy(pp);
    }
    catch (Exception e)
    {
      return null;
    }
  }


private static String[] getUserProxy(Object pp) throws Exception
{
    String[] userProxy = new String[3];

    String className = "android.net.ProxyProperties";
    Class<?> c = Class.forName(className);
    Method method;

    method = c.getMethod("getHost");
    userProxy[0] = (String) method.invoke(pp);

    method = c.getMethod("getPort");
    userProxy[1] = String.valueOf((Integer) method.invoke(pp));


    method = c.getMethod("getExclusionList");
    userProxy[2] = (String) method.invoke(pp);

    if (userProxy[0] != null)
      return userProxy;
    else
      return null;
}

댓글 없음:

댓글 쓰기

eclipse rcp dialog resize

  Dialog 안에 메소드를 만든다. private void autoResize(){     getShell().layout( true, true);     final Point newSize = getShell().computeSize...