gpt4 book ai didi

java.lang.NoSuchMethodException : getTetherableIfaces on Lollipop 异常

转载 作者:行者123 更新时间:2023-11-30 02:02:30 38 4
gpt4 key购买 nike

我的应用程序需要检查是否有可用的 USB 可连接接口(interface)。为此,它使用反射在 ConnectivityManager 上调用 getTetherableIfaces。

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 而失败。

此功能在 Lollipop 中是否被删除或更改?

最佳答案

根据 http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.1_r1/android/net/ConnectivityManager.java#ConnectivityManager.getTetherableIfaces%28%29该方法仍然存在。

也许您应该改为尝试 ConnectivityManager.class.getDeclaredMethod("getTetherableIfaces")

您是否尝试查看连接管理器的所有方法列表?您能向我们展示以下代码的日志吗。

Method[] methodArray = ConnectivityManager.class.getMethods();
for (Method method : methodArray) {
Log.v(TAG, method.getName());
}

关于java.lang.NoSuchMethodException : getTetherableIfaces on Lollipop 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31269110/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com