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

巧了我就是萌 提交于 2019-12-10 11:16:07

问题


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.


回答1:


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:

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 physical device that located in /system/framework/framework.jar to here. I will make a new!

ANOTHER LIMITATION

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 is only able to access them within appropriate device's API level. For example, you use android.net.EthernetManager within your app, you 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, 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.




回答2:


IIRC you can only do this if your device is rooted.

There's a good explanation here: Ethernet Connectivity through Programatically (Android) (Rooted Device)



来源:https://stackoverflow.com/questions/35215533/is-there-a-way-to-access-android-net-ethernetmanager-in-an-android-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!