如何使用来自Android /内部/电话/电话的GetAvailableNetWorks.java
-
09-12-2019 - |
题
我有一个要求,我需要开发Nexus s的Android应用程序,以获取我周围的所有可用网络运营商。
我一直在跟进很多博客来完成这项。
首先,它是一个内部/隐藏API
所以我遵循这种方法调用它。
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManagerClass = Class.forName(telephonyManager.getClass().getName());
Method getITelephonyMethod = telephonyManagerClass.getDeclaredMethod("getITelephony");
getITelephonyMethod.setAccessible(true);
ITelephonyStub = getITelephonyMethod.invoke(telephonyManager);
ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName());
setPrefNetmethod = ITelephonyClass.getDeclaredMethod(
"getAvailableNetworks", new Class[] { Message.class });
Message response = Message.obtain();
setPrefNetmethod.setAccessible(false);
setPrefNetmethod.invoke(ITelephonyStub, new Object[] { network_mode, response });
.
但我得到setPrefNetMethod= null始终...
我甚至在Android Manifest ... 中设置了生成的<uses-permission android:name="android.permission.READ_PHONE_STATE" />
任何帮助对我来说都是很棒的。
解决方案
只是看看Itelephony对象上有哪些方法,而不是使用getDeclaredMethod()尝试:
Method[] methods = ITelephonyClass.getDeclaredMethods();
for (Method method : methods) {
Log.i("Method", "Method name is: "+method.getName());
}
.
这应该记录可用方法的列表。也许有一个看起来它会帮助你。找到所需的方法后,您还可以调用Method.getParameterTypes(),它将返回类名数组。这将告诉您方法期望的参数。 但是,您可能无法执行您想要的操作,因为每个制造商都可以自由地更改此内容,因为它们认为适合。
不隶属于 StackOverflow