java.lang.NoSuchMethodException:在棒棒糖上获取etherableIfaces
我的应用程序需要检查是否有可用的USB连接接口。为此,它使用反射在ConnectionManager上调用GetEtherableIfacesjava.lang.NoSuchMethodException:在棒棒糖上获取etherableIfaces,java,android,android-5.0-lollipop,Java,Android,Android 5.0 Lollipop,我的应用程序需要检查是否有可用的USB连接接口。为此,它使用反射在ConnectionManager上调用GetEtherableIfaces ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); Class cmClass = Class.forName(cm.getClass().getName()); Method method = cmC
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Class cmClass = Class.forName(cm.getClass().getName());
Method method = cmClass.getDeclaredMethod("getTetherableIfaces");
method.setAccessible(true);
method.invoke(cm, args);
我已经在运行Android 5.0.1的LG Leon上测试过了,它失败了,出现了java.lang.NoSuchMethodException
棒棒糖中是否已删除或更改此功能?根据该方法,此功能仍然存在
也许你应该试试
ConnectivityManager.class.getDeclaredMethod(“getEtherTableIfaces”)
您是否尝试查看connectivity manager的所有方法列表?你能给我们看一下下面代码的日志吗
Method[] methodArray = ConnectivityManager.class.getMethods();
for (Method method : methodArray) {
Log.v(TAG, method.getName());
}
ConnectionManager.class.getDeclaredMethod有效,谢谢。调试完设备后,我发现context.getSystemService(context.CONNECTIVITY_SERVICE)返回ConnectivityManager的子类,在此实例上调用getDeclaredMethod只返回子类的方法,而不是ConnectivityManager中的方法。调用getMethod是正确的解决方案。