dimanche 1 mai 2016

Set static IP using reflection in Android 5.0 and above

I've tried the solution posted here How to configure a static IP address, netmask, gateway, DNS programmatically on Android 5.x (Lollipop) for Wi-Fi connection

But, when I run, I get following error

com.packagename W/System.err: at com.packagename.classname.getEnumValue(class-name.java:175)

Here getEnumValue() method says

private static Object getEnumValue(String enumClassName, String enumValue) throws ClassNotFoundException
{
    Class<Enum> enumClz = (Class<Enum>)Class.forName(enumClassName);
    return Enum.valueOf(enumClz, enumValue);
}

Here in my code 175th line is,

Class<Enum> enumClz = (Class<Enum>)Class.forName(enumClassName);

where

enunClassName = "android.net.IpConfiguration$IpAssignment"

getEnumValue() method is called using

Object ipAssignment = getEnumValue("android.net.IpConfiguration$IpAssignment", "STATIC");

I'm running this code for API 21 as suggested in above link too.

Thanks in advance...





Aucun commentaire:

Enregistrer un commentaire