Reputation: 269
I'm looking for a way to identify the input device that is external.
I notice the Android API for [InputDevice] class have a function called [isExternal]. But when I tried to use it, it tells me that it cannot resolve method. I check the online API reference and notice that the function does not exist. So I wonder why is the function in the API but not in the online reference.
Reference: https://developer.android.com/reference/android/view/InputDevice.html https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/view/InputDevice.java
Upvotes: 2
Views: 613
Reputation: 66
isExternal is a hidden method that is not accessible through the SDK. However, you can still invoke it using java reflection.
public boolean isExternal(InputDevice inputDevice) {
try {
Method m = InputDevice.class.getMethod("isExternal");
return (Boolean) m.invoke(inputDevice);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
return false;
}
}
source: What does @hide mean in the Android source code?
Upvotes: 5