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.
2 Answers
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, whereas 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 thrown, for example java.lang.NoClassDefFoundError
, because android.net.EthernetManager
class is built only for API 22 and higher.

- 14,977
- 11
- 54
- 87
-
Thanks a lot. I will give it a shot and report back tomorrow. – Hong Feb 05 '16 at 04:44
-
I have just tried it. I got an error: java.lang.NoClassDefFoundError: android.net.EthernetManager. I am wondering if the testing device is an API 19, then I have to use android-19. In other words, if I build the app with target API 19, that app can be deployed ONLY to the API 19 devices. Could you clarify this? – Hong Feb 05 '16 at 16:11
-
Thank you. How can one find out which API is available only for which API? I cannot figure out EthernetManager is available only for API 22 and above by looking at the code. – Hong Feb 06 '16 at 23:56
-
1@Hong, Just type method, resource or class to searchbox on http://jcs.mobile-utopia.com/servlet/Source?type=s&q=android.net.EthernetManager. And then, look at **Category** column. – Anggrayudi H Feb 07 '16 at 04:54
-
Thank you. I am wondering if that method is reliable because the android.jar of the Android Hidden API library for API 21 has EthernetManager. I want to use it for API 17, so I am out of luck. – Hong Feb 07 '16 at 05:48
-
Just my 5 cents. Using unhidden classes is good idea but it increases your app on 5Mb, remember about it. I had have to drop this effort. – djdance Dec 03 '18 at 12:40
-
@djdance That is why you need to shrink your code with ProGuard. – Anggrayudi H Dec 05 '18 at 17:30
-
@AnggrayudiH you seem to be the most concerned person with AOSP's hidden APIs. Thanks for your work. // Giving an example, `IPackageManager#getPermissionFlags()` is replaced with `IPermissionManager#getPermissionFlags()` in SDK 30. So when targeting SDK 30 the former is not accessible and compiler throws `symbol not found`. Is there any way other than 1) `reflection` or 2) modified `android.jar` that we can opt to access the hidden APIs? – Irfan Latif Dec 28 '20 at 02:34
-
1The only solution for this case is using reflection, and check API level before calling `getPermissionFlags()`. Java reflection can be used in dynamic situation like this. @IrfanLatif – Anggrayudi H Dec 28 '20 at 05:11
-
@AnggrayudiH exactly that's what I'm doing. In fact both solutions work. I added stub `getPermissionFlags()` to `IPackageManager.class` (which is an AIDL interface to `PackageManagerService`) in `android.jar` and no more compilation errors. But you have good experience with this. So I thought might be you have some third idea too. Anyway thanks for responding. – Irfan Latif Dec 28 '20 at 16:48
IIRC you can only do this if your device is rooted.
There's a good explanation here: Ethernet Connectivity through Programatically (Android) (Rooted Device)
-
Thank you for the answer. I looked at the post before. I get null for getSystemService("ethernet") on a rooted device. – Hong Feb 05 '16 at 13:15