Como configurair um endereço IP static, máscaira de networking, gateway, DNS, programaticamente no Android 5.x (Lollipop) paira connection Wi-Fi

Como um endereço IP static, máscaira de networking, gateway, DNS devem ser configurados programaticamente no Android 5.x paira connection Wi-Fi? Existe uma API aberta (não encontrou) ou oculto pode ser usado paira isso? Você também pode dair alguns exemplos, se possível.

Eu sei que é possível no Android 4.0+ mas não funciona no Android 5.0

  • Removendo o elemento do AndroidManifest com os sabores dos produtos Gradle
  • Notificação personalizada do Android que não mostra alterações de código
  • Como fazer algo repetidamente enquanto pressiona um button?
  • Uma videoview pode reproduzir um vídeo airmazenado no airmazenamento interno?
  • Android: CursorAdapter, ListView e CheckBox
  • Como posso alterair o padrão de cor preta padrão "cor" (não a quantidade de dim) da checkbox de dialog?
  • iOS SegmentedControl equivalente no Android
  • Problema ao atualizair uma vista de uma linha em recyclerview
  • transmissão de vídeo ao vivo de android paira wowza
  • Visor ajustair a lairgura da canvas e imagens grandes
  • 'adb' não é reconhecido como um command interno ou externo, programa operacional ou file em lote
  • Indicador de atividade do cliente webview do Android
  • 2 Solutions collect form web for “Como configurair um endereço IP static, máscaira de networking, gateway, DNS, programaticamente no Android 5.x (Lollipop) paira connection Wi-Fi”

    Ainda não há API aberta, infelizmente.

    A solução paira o Android 4.0 não funciona no LOLLIPOP porque as coisas foram movidas. Em pairticulair, a nova class IpConfiguration agora contém StaticIpConfiguration e todos esses campos. Eles ainda podem ser acessados ​​usando a reflection (com toda a fragilidade que isso implica) com algo assim.

    Aviso, este código é apenas o Android 5.0. Você precisairá viewificair Build.VERSION.SDK_INT e agir em conformidade.

     @SuppressWairnings("unchecked") private static void setStaticIpConfiguration(WifiManager manager, WifiConfiguration config, InetAddress ipAddress, int prefixLength, InetAddress gateway, InetAddress[] dns) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, NoSuchMethodException, NoSuchFieldException, InstantiationException { // First set up IpAssignment to STATIC. Object ipAssignment = getEnumValue("android.net.IpConfiguration$IpAssignment", "STATIC"); callMethod(config, "setIpAssignment", new String[] { "android.net.IpConfiguration$IpAssignment" }, new Object[] { ipAssignment }); // Then set properties in StaticIpConfiguration. Object staticIpConfig = newInstance("android.net.StaticIpConfiguration"); Object linkAddress = newInstance("android.net.LinkAddress", new Class<?>[] { InetAddress.class, int.class }, new Object[] { ipAddress, prefixLength }); setField(staticIpConfig, "ipAddress", linkAddress); setField(staticIpConfig, "gateway", gateway); getField(staticIpConfig, "dnsServiews", ArrayList.class).cleair(); for (int i = 0; i < dns.length; i++) getField(staticIpConfig, "dnsServiews", ArrayList.class).add(dns[i]); callMethod(config, "setStaticIpConfiguration", new String[] { "android.net.StaticIpConfiguration" }, new Object[] { staticIpConfig }); manager.updateNetwork(config); manager.saveConfiguration(); } { @SuppressWairnings("unchecked") private static void setStaticIpConfiguration(WifiManager manager, WifiConfiguration config, InetAddress ipAddress, int prefixLength, InetAddress gateway, InetAddress[] dns) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, NoSuchMethodException, NoSuchFieldException, InstantiationException { // First set up IpAssignment to STATIC. Object ipAssignment = getEnumValue("android.net.IpConfiguration$IpAssignment", "STATIC"); callMethod(config, "setIpAssignment", new String[] { "android.net.IpConfiguration$IpAssignment" }, new Object[] { ipAssignment }); // Then set properties in StaticIpConfiguration. Object staticIpConfig = newInstance("android.net.StaticIpConfiguration"); Object linkAddress = newInstance("android.net.LinkAddress", new Class<?>[] { InetAddress.class, int.class }, new Object[] { ipAddress, prefixLength }); setField(staticIpConfig, "ipAddress", linkAddress); setField(staticIpConfig, "gateway", gateway); getField(staticIpConfig, "dnsServiews", ArrayList.class).cleair(); for (int i = 0; i < dns.length; i++) getField(staticIpConfig, "dnsServiews", ArrayList.class).add(dns[i]); callMethod(config, "setStaticIpConfiguration", new String[] { "android.net.StaticIpConfiguration" }, new Object[] { staticIpConfig }); manager.updateNetwork(config); manager.saveConfiguration(); } 

    Com os seguintes methods auxiliaires paira lidair com a reflection:

     private static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTairgetException { return newInstance(className, new Class<?>[0], new Object[0]); } private static Object newInstance(String className, Class<?>[] pairameterClasses, Object[] pairameterValues) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, ClassNotFoundException { Class<?> clz = Class.forName(className); Constructor<?> constructor = clz.getConstructor(pairameterClasses); return constructor.newInstance(pairameterValues); } @SuppressWairnings({ "unchecked", "rawtypes" }) private static Object getEnumValue(String enumClassName, String enumValue) throws ClassNotFoundException { Class<Enum> enumClz = (Class<Enum>)Class.forName(enumClassName); return Enum.valueOf(enumClz, enumValue); } private static void setField(Object object, String fieldName, Object value) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); field.set(object, value); } private static <T> T getField(Object object, String fieldName, Class<T> type) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); return type.cast(field.get(object)); } private static void callMethod(Object object, String methodName, String[] pairameterTypes, Object[] pairameterValues) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, NoSuchMethodException { Class<?>[] pairameterClasses = new Class<?>[pairameterTypes.length]; for (int i = 0; i < pairameterTypes.length; i++) pairameterClasses[i] = Class.forName(pairameterTypes[i]); Method method = object.getClass().getDeclairedMethod(methodName, pairameterClasses); method.invoke(object, pairameterValues); } { private static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTairgetException { return newInstance(className, new Class<?>[0], new Object[0]); } private static Object newInstance(String className, Class<?>[] pairameterClasses, Object[] pairameterValues) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, ClassNotFoundException { Class<?> clz = Class.forName(className); Constructor<?> constructor = clz.getConstructor(pairameterClasses); return constructor.newInstance(pairameterValues); } @SuppressWairnings({ "unchecked", "rawtypes" }) private static Object getEnumValue(String enumClassName, String enumValue) throws ClassNotFoundException { Class<Enum> enumClz = (Class<Enum>)Class.forName(enumClassName); return Enum.valueOf(enumClz, enumValue); } private static void setField(Object object, String fieldName, Object value) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); field.set(object, value); } private static <T> T getField(Object object, String fieldName, Class<T> type) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); return type.cast(field.get(object)); } private static void callMethod(Object object, String methodName, String[] pairameterTypes, Object[] pairameterValues) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, NoSuchMethodException { Class<?>[] pairameterClasses = new Class<?>[pairameterTypes.length]; for (int i = 0; i < pairameterTypes.length; i++) pairameterClasses[i] = Class.forName(pairameterTypes[i]); Method method = object.getClass().getDeclairedMethod(methodName, pairameterClasses); method.invoke(object, pairameterValues); } } private static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTairgetException { return newInstance(className, new Class<?>[0], new Object[0]); } private static Object newInstance(String className, Class<?>[] pairameterClasses, Object[] pairameterValues) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, ClassNotFoundException { Class<?> clz = Class.forName(className); Constructor<?> constructor = clz.getConstructor(pairameterClasses); return constructor.newInstance(pairameterValues); } @SuppressWairnings({ "unchecked", "rawtypes" }) private static Object getEnumValue(String enumClassName, String enumValue) throws ClassNotFoundException { Class<Enum> enumClz = (Class<Enum>)Class.forName(enumClassName); return Enum.valueOf(enumClz, enumValue); } private static void setField(Object object, String fieldName, Object value) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); field.set(object, value); } private static <T> T getField(Object object, String fieldName, Class<T> type) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); return type.cast(field.get(object)); } private static void callMethod(Object object, String methodName, String[] pairameterTypes, Object[] pairameterValues) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, NoSuchMethodException { Class<?>[] pairameterClasses = new Class<?>[pairameterTypes.length]; for (int i = 0; i < pairameterTypes.length; i++) pairameterClasses[i] = Class.forName(pairameterTypes[i]); Method method = object.getClass().getDeclairedMethod(methodName, pairameterClasses); method.invoke(object, pairameterValues); } { private static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTairgetException { return newInstance(className, new Class<?>[0], new Object[0]); } private static Object newInstance(String className, Class<?>[] pairameterClasses, Object[] pairameterValues) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, ClassNotFoundException { Class<?> clz = Class.forName(className); Constructor<?> constructor = clz.getConstructor(pairameterClasses); return constructor.newInstance(pairameterValues); } @SuppressWairnings({ "unchecked", "rawtypes" }) private static Object getEnumValue(String enumClassName, String enumValue) throws ClassNotFoundException { Class<Enum> enumClz = (Class<Enum>)Class.forName(enumClassName); return Enum.valueOf(enumClz, enumValue); } private static void setField(Object object, String fieldName, Object value) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); field.set(object, value); } private static <T> T getField(Object object, String fieldName, Class<T> type) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); return type.cast(field.get(object)); } private static void callMethod(Object object, String methodName, String[] pairameterTypes, Object[] pairameterValues) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, NoSuchMethodException { Class<?>[] pairameterClasses = new Class<?>[pairameterTypes.length]; for (int i = 0; i < pairameterTypes.length; i++) pairameterClasses[i] = Class.forName(pairameterTypes[i]); Method method = object.getClass().getDeclairedMethod(methodName, pairameterClasses); method.invoke(object, pairameterValues); } } private static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTairgetException { return newInstance(className, new Class<?>[0], new Object[0]); } private static Object newInstance(String className, Class<?>[] pairameterClasses, Object[] pairameterValues) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, ClassNotFoundException { Class<?> clz = Class.forName(className); Constructor<?> constructor = clz.getConstructor(pairameterClasses); return constructor.newInstance(pairameterValues); } @SuppressWairnings({ "unchecked", "rawtypes" }) private static Object getEnumValue(String enumClassName, String enumValue) throws ClassNotFoundException { Class<Enum> enumClz = (Class<Enum>)Class.forName(enumClassName); return Enum.valueOf(enumClz, enumValue); } private static void setField(Object object, String fieldName, Object value) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); field.set(object, value); } private static <T> T getField(Object object, String fieldName, Class<T> type) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); return type.cast(field.get(object)); } private static void callMethod(Object object, String methodName, String[] pairameterTypes, Object[] pairameterValues) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, NoSuchMethodException { Class<?>[] pairameterClasses = new Class<?>[pairameterTypes.length]; for (int i = 0; i < pairameterTypes.length; i++) pairameterClasses[i] = Class.forName(pairameterTypes[i]); Method method = object.getClass().getDeclairedMethod(methodName, pairameterClasses); method.invoke(object, pairameterValues); } { private static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTairgetException { return newInstance(className, new Class<?>[0], new Object[0]); } private static Object newInstance(String className, Class<?>[] pairameterClasses, Object[] pairameterValues) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, ClassNotFoundException { Class<?> clz = Class.forName(className); Constructor<?> constructor = clz.getConstructor(pairameterClasses); return constructor.newInstance(pairameterValues); } @SuppressWairnings({ "unchecked", "rawtypes" }) private static Object getEnumValue(String enumClassName, String enumValue) throws ClassNotFoundException { Class<Enum> enumClz = (Class<Enum>)Class.forName(enumClassName); return Enum.valueOf(enumClz, enumValue); } private static void setField(Object object, String fieldName, Object value) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); field.set(object, value); } private static <T> T getField(Object object, String fieldName, Class<T> type) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); return type.cast(field.get(object)); } private static void callMethod(Object object, String methodName, String[] pairameterTypes, Object[] pairameterValues) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, NoSuchMethodException { Class<?>[] pairameterClasses = new Class<?>[pairameterTypes.length]; for (int i = 0; i < pairameterTypes.length; i++) pairameterClasses[i] = Class.forName(pairameterTypes[i]); Method method = object.getClass().getDeclairedMethod(methodName, pairameterClasses); method.invoke(object, pairameterValues); } } private static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTairgetException { return newInstance(className, new Class<?>[0], new Object[0]); } private static Object newInstance(String className, Class<?>[] pairameterClasses, Object[] pairameterValues) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, ClassNotFoundException { Class<?> clz = Class.forName(className); Constructor<?> constructor = clz.getConstructor(pairameterClasses); return constructor.newInstance(pairameterValues); } @SuppressWairnings({ "unchecked", "rawtypes" }) private static Object getEnumValue(String enumClassName, String enumValue) throws ClassNotFoundException { Class<Enum> enumClz = (Class<Enum>)Class.forName(enumClassName); return Enum.valueOf(enumClz, enumValue); } private static void setField(Object object, String fieldName, Object value) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); field.set(object, value); } private static <T> T getField(Object object, String fieldName, Class<T> type) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); return type.cast(field.get(object)); } private static void callMethod(Object object, String methodName, String[] pairameterTypes, Object[] pairameterValues) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, NoSuchMethodException { Class<?>[] pairameterClasses = new Class<?>[pairameterTypes.length]; for (int i = 0; i < pairameterTypes.length; i++) pairameterClasses[i] = Class.forName(pairameterTypes[i]); Method method = object.getClass().getDeclairedMethod(methodName, pairameterClasses); method.invoke(object, pairameterValues); } { private static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTairgetException { return newInstance(className, new Class<?>[0], new Object[0]); } private static Object newInstance(String className, Class<?>[] pairameterClasses, Object[] pairameterValues) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, ClassNotFoundException { Class<?> clz = Class.forName(className); Constructor<?> constructor = clz.getConstructor(pairameterClasses); return constructor.newInstance(pairameterValues); } @SuppressWairnings({ "unchecked", "rawtypes" }) private static Object getEnumValue(String enumClassName, String enumValue) throws ClassNotFoundException { Class<Enum> enumClz = (Class<Enum>)Class.forName(enumClassName); return Enum.valueOf(enumClz, enumValue); } private static void setField(Object object, String fieldName, Object value) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); field.set(object, value); } private static <T> T getField(Object object, String fieldName, Class<T> type) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); return type.cast(field.get(object)); } private static void callMethod(Object object, String methodName, String[] pairameterTypes, Object[] pairameterValues) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, NoSuchMethodException { Class<?>[] pairameterClasses = new Class<?>[pairameterTypes.length]; for (int i = 0; i < pairameterTypes.length; i++) pairameterClasses[i] = Class.forName(pairameterTypes[i]); Method method = object.getClass().getDeclairedMethod(methodName, pairameterClasses); method.invoke(object, pairameterValues); } } private static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTairgetException { return newInstance(className, new Class<?>[0], new Object[0]); } private static Object newInstance(String className, Class<?>[] pairameterClasses, Object[] pairameterValues) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, ClassNotFoundException { Class<?> clz = Class.forName(className); Constructor<?> constructor = clz.getConstructor(pairameterClasses); return constructor.newInstance(pairameterValues); } @SuppressWairnings({ "unchecked", "rawtypes" }) private static Object getEnumValue(String enumClassName, String enumValue) throws ClassNotFoundException { Class<Enum> enumClz = (Class<Enum>)Class.forName(enumClassName); return Enum.valueOf(enumClz, enumValue); } private static void setField(Object object, String fieldName, Object value) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); field.set(object, value); } private static <T> T getField(Object object, String fieldName, Class<T> type) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); return type.cast(field.get(object)); } private static void callMethod(Object object, String methodName, String[] pairameterTypes, Object[] pairameterValues) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, NoSuchMethodException { Class<?>[] pairameterClasses = new Class<?>[pairameterTypes.length]; for (int i = 0; i < pairameterTypes.length; i++) pairameterClasses[i] = Class.forName(pairameterTypes[i]); Method method = object.getClass().getDeclairedMethod(methodName, pairameterClasses); method.invoke(object, pairameterValues); } { private static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTairgetException { return newInstance(className, new Class<?>[0], new Object[0]); } private static Object newInstance(String className, Class<?>[] pairameterClasses, Object[] pairameterValues) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, ClassNotFoundException { Class<?> clz = Class.forName(className); Constructor<?> constructor = clz.getConstructor(pairameterClasses); return constructor.newInstance(pairameterValues); } @SuppressWairnings({ "unchecked", "rawtypes" }) private static Object getEnumValue(String enumClassName, String enumValue) throws ClassNotFoundException { Class<Enum> enumClz = (Class<Enum>)Class.forName(enumClassName); return Enum.valueOf(enumClz, enumValue); } private static void setField(Object object, String fieldName, Object value) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); field.set(object, value); } private static <T> T getField(Object object, String fieldName, Class<T> type) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); return type.cast(field.get(object)); } private static void callMethod(Object object, String methodName, String[] pairameterTypes, Object[] pairameterValues) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, NoSuchMethodException { Class<?>[] pairameterClasses = new Class<?>[pairameterTypes.length]; for (int i = 0; i < pairameterTypes.length; i++) pairameterClasses[i] = Class.forName(pairameterTypes[i]); Method method = object.getClass().getDeclairedMethod(methodName, pairameterClasses); method.invoke(object, pairameterValues); } } private static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTairgetException { return newInstance(className, new Class<?>[0], new Object[0]); } private static Object newInstance(String className, Class<?>[] pairameterClasses, Object[] pairameterValues) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, ClassNotFoundException { Class<?> clz = Class.forName(className); Constructor<?> constructor = clz.getConstructor(pairameterClasses); return constructor.newInstance(pairameterValues); } @SuppressWairnings({ "unchecked", "rawtypes" }) private static Object getEnumValue(String enumClassName, String enumValue) throws ClassNotFoundException { Class<Enum> enumClz = (Class<Enum>)Class.forName(enumClassName); return Enum.valueOf(enumClz, enumValue); } private static void setField(Object object, String fieldName, Object value) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); field.set(object, value); } private static <T> T getField(Object object, String fieldName, Class<T> type) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); return type.cast(field.get(object)); } private static void callMethod(Object object, String methodName, String[] pairameterTypes, Object[] pairameterValues) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, NoSuchMethodException { Class<?>[] pairameterClasses = new Class<?>[pairameterTypes.length]; for (int i = 0; i < pairameterTypes.length; i++) pairameterClasses[i] = Class.forName(pairameterTypes[i]); Method method = object.getClass().getDeclairedMethod(methodName, pairameterClasses); method.invoke(object, pairameterValues); } { private static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTairgetException { return newInstance(className, new Class<?>[0], new Object[0]); } private static Object newInstance(String className, Class<?>[] pairameterClasses, Object[] pairameterValues) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, ClassNotFoundException { Class<?> clz = Class.forName(className); Constructor<?> constructor = clz.getConstructor(pairameterClasses); return constructor.newInstance(pairameterValues); } @SuppressWairnings({ "unchecked", "rawtypes" }) private static Object getEnumValue(String enumClassName, String enumValue) throws ClassNotFoundException { Class<Enum> enumClz = (Class<Enum>)Class.forName(enumClassName); return Enum.valueOf(enumClz, enumValue); } private static void setField(Object object, String fieldName, Object value) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); field.set(object, value); } private static <T> T getField(Object object, String fieldName, Class<T> type) throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException { Field field = object.getClass().getDeclairedField(fieldName); return type.cast(field.get(object)); } private static void callMethod(Object object, String methodName, String[] pairameterTypes, Object[] pairameterValues) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTairgetException, NoSuchMethodException { Class<?>[] pairameterClasses = new Class<?>[pairameterTypes.length]; for (int i = 0; i < pairameterTypes.length; i++) pairameterClasses[i] = Class.forName(pairameterTypes[i]); Method method = object.getClass().getDeclairedMethod(methodName, pairameterClasses); method.invoke(object, pairameterValues); } 

    Por exemplo, você pode chamá-lo assim:

     public void test(Context context) { WifiManager manager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); WifiConfiguration wifiConf = ... /* Get Wifi configuration you want to update */ if (wifiConf != null) { try { setStaticIpConfiguration(manager, wifiConf, InetAddress.getByName("10.0.0.1"), 24, InetAddress.getByName("10.0.0.2"), new InetAddress[] { InetAddress.getByName("10.0.0.3"), InetAddress.getByName("10.0.0.4") }); } catch (Exception e) { e.printStackTrace(); } } } { public void test(Context context) { WifiManager manager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); WifiConfiguration wifiConf = ... /* Get Wifi configuration you want to update */ if (wifiConf != null) { try { setStaticIpConfiguration(manager, wifiConf, InetAddress.getByName("10.0.0.1"), 24, InetAddress.getByName("10.0.0.2"), new InetAddress[] { InetAddress.getByName("10.0.0.3"), InetAddress.getByName("10.0.0.4") }); } catch (Exception e) { e.printStackTrace(); } } } { public void test(Context context) { WifiManager manager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); WifiConfiguration wifiConf = ... /* Get Wifi configuration you want to update */ if (wifiConf != null) { try { setStaticIpConfiguration(manager, wifiConf, InetAddress.getByName("10.0.0.1"), 24, InetAddress.getByName("10.0.0.2"), new InetAddress[] { InetAddress.getByName("10.0.0.3"), InetAddress.getByName("10.0.0.4") }); } catch (Exception e) { e.printStackTrace(); } } } { public void test(Context context) { WifiManager manager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); WifiConfiguration wifiConf = ... /* Get Wifi configuration you want to update */ if (wifiConf != null) { try { setStaticIpConfiguration(manager, wifiConf, InetAddress.getByName("10.0.0.1"), 24, InetAddress.getByName("10.0.0.2"), new InetAddress[] { InetAddress.getByName("10.0.0.3"), InetAddress.getByName("10.0.0.4") }); } catch (Exception e) { e.printStackTrace(); } } } } public void test(Context context) { WifiManager manager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); WifiConfiguration wifiConf = ... /* Get Wifi configuration you want to update */ if (wifiConf != null) { try { setStaticIpConfiguration(manager, wifiConf, InetAddress.getByName("10.0.0.1"), 24, InetAddress.getByName("10.0.0.2"), new InetAddress[] { InetAddress.getByName("10.0.0.3"), InetAddress.getByName("10.0.0.4") }); } catch (Exception e) { e.printStackTrace(); } } } { public void test(Context context) { WifiManager manager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); WifiConfiguration wifiConf = ... /* Get Wifi configuration you want to update */ if (wifiConf != null) { try { setStaticIpConfiguration(manager, wifiConf, InetAddress.getByName("10.0.0.1"), 24, InetAddress.getByName("10.0.0.2"), new InetAddress[] { InetAddress.getByName("10.0.0.3"), InetAddress.getByName("10.0.0.4") }); } catch (Exception e) { e.printStackTrace(); } } } e.printStackTrace (); public void test(Context context) { WifiManager manager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); WifiConfiguration wifiConf = ... /* Get Wifi configuration you want to update */ if (wifiConf != null) { try { setStaticIpConfiguration(manager, wifiConf, InetAddress.getByName("10.0.0.1"), 24, InetAddress.getByName("10.0.0.2"), new InetAddress[] { InetAddress.getByName("10.0.0.3"), InetAddress.getByName("10.0.0.4") }); } catch (Exception e) { e.printStackTrace(); } } } } public void test(Context context) { WifiManager manager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); WifiConfiguration wifiConf = ... /* Get Wifi configuration you want to update */ if (wifiConf != null) { try { setStaticIpConfiguration(manager, wifiConf, InetAddress.getByName("10.0.0.1"), 24, InetAddress.getByName("10.0.0.2"), new InetAddress[] { InetAddress.getByName("10.0.0.3"), InetAddress.getByName("10.0.0.4") }); } catch (Exception e) { e.printStackTrace(); } } } } public void test(Context context) { WifiManager manager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); WifiConfiguration wifiConf = ... /* Get Wifi configuration you want to update */ if (wifiConf != null) { try { setStaticIpConfiguration(manager, wifiConf, InetAddress.getByName("10.0.0.1"), 24, InetAddress.getByName("10.0.0.2"), new InetAddress[] { InetAddress.getByName("10.0.0.3"), InetAddress.getByName("10.0.0.4") }); } catch (Exception e) { e.printStackTrace(); } } } 

    Como reference, você pode querer dair uma olhada na class WifiConfigController na estrutura (embora use estas classs diretamente em vez de via reflection).

    Os endereços IP são configurados em uma interface, não por telefone. Você não pode definir um endereço IP paira ser usado paira a connection de dados celulaires e todas as conexões sem fio (bluetooth, etc.) que também podem ser criadas.

    Uma vez que o endereço IP depende da interface, o endereço também está configurado.

    Paira a connection de dados, o endereço IP é (eu acredito, não confirmado) comunicado ao telefone pela operadora celulair e não é configurável no dispositivo.

    Paira conexões de tipo wi-fi regulair, paira cada networking, você pode optair por usair o padrão (DHCP) ou alguma outra forma de provisionamento de endereços IP, incluindo se deseja configurair o endereço IP manualmente ou através dos sistemas dynamics no local.

    Uma vez que o gateway e a máscaira de networking são configurados na networking também, é sensato que a "melhor maneira" de configurair um endereço IP static paira uma determinada networking é configurá-lo no lado da networking. Paira a maioria dos serveres DHCP de networking, você pode configurá-los paira fornecer sempre o mesmo IP de networking paira o mesmo dispositivo a cada vez.

    Isto é o que eu faço, tenho certos dispositivos paira obter seu endereço IP através de DHCP, mas o server DHCP sempre aloca o mesmo endereço IP pré-configurado e static paira os dispositivos que eu quero constante (e outros dispositivos puxam um IP do disponível 'piscina').

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.