Hong Hong - 1 year ago 157
Android Question

Is there a way to access android.net.EthernetManager in an Android app?

Is there a way to access android.net.EthernetManager in an Android app?
Both Class.forName("android.net.ethernet.EthernetManager") and Class.forName("android.net.EthernetManager") generate a ClassNotFoundException.

Answer Source

Seems that android.net.EthernetManager is a hidden class, marked as @hide by Javadoc. You can access it by using customized SDK platform which was made here, and you don't need to root the device.

Android Hidden API library is a modified jar file which combines android.jar from Android SDK with framework.jar from real device. This jar makes you able to use Android internal/hidden APIs in development.

What is Android internal and hidden APIs? Internal API is located in com.android.internal package which is available in the framework.jar file from real Android device, while hidden API is located in android.jar file with @hide Javadoc attribute. Although the classes & methods are public, but you cannot access it. There are pretty methods and resources you can use from this package. I will assume this is one API and will refer to it as to hidden API. Learn more about hidden API here.

So, look at this @hide mark:

enter image description here

This class is available on API level 22 and higher. But, the customized API has limitation. Android Hidden API is not available for Lollipop 5.1.1 (API 22) and Marshmallow 6.0 (API 23), because of I can't find any people who has this device. If you have it, please upload framework.jar file from real device that located in /system/framework/framework.jar to here. I will make a new!


There's another limitation from Hidden API that I don't explain yet. When you use some features, methods, resources or classes with this hidden API, which are only available on certain API level, your app only able to access them within appropriate device's API level. For example, you use android.net.EthernetManager within your app, your have to set the target & compile SDK to android-22 (because this class is only available on API level 22 and higher). Once you run your app on a device which has API level 22 and higher, there's no error is showed. But, once you run the app on API level 21 and lower, an error will be threw, for example java.lang.NoClassDefFoundError, because android.net.EthernetManager class is built only for API 22 and higher.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download