简体   繁体   English

Android 4.2.2 Wifi-Direct adhoc网络 - 访问隐藏的android方法来设置SSID和密码?

[英]Android 4.2.2 Wifi-Direct adhoc network – accessing hidden android methods to set the SSID and passphrase?

I have successfully set up an Android peer-to-peer Wifi-Direct group using the WifiP2pManager “createGroup()” method. 我已经使用WifiP2pManager“createGroup()”方法成功建立了一个Android对等Wifi-Direct组。 My Android (4.2.2) device is configured as the group owner. 我的Android(4.2.2)设备被配置为组所有者。 Now I need to set the SSID and the passphrase for adhoc communication with a legacy wifi peer device that I would like to connect to. 现在,我需要设置SSID和密码,以便与我想要连接的传统wifi对等设备进行adhoc通信。

Android seems to set up a default SSID and passphrase and I am able to read these values using the WifiP2pGroup “getNetworkname()” and “getPassphrase()” methods. Android似乎设置了默认的SSID和密码,我可以使用WifiP2pGroup“getNetworkname()”和“getPassphrase()”方法读取这些值。 I could use these values, but I want to instead set the values dynamically in my code to match the values of the legacy wifi device that I would like to connect to. 我可以使用这些值,但我想在我的代码中动态设置值,以匹配我想要连接的传统wifi设备的值。

If you look through the android code for the WifiP2pGroup, listed at: 如果你查看WifiP2pGroup的android代码,列在:

http://android.googlesource.com/platform/frameworks/base/+/cd92588/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java http://android.googlesource.com/platform/frameworks/base/+/cd92588/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java

you can see that the public methods “setNetworkName()” and “setPassphrase()” do indeed exist. 你可以看到公共方法“setNetworkName()”和“setPassphrase()”确实存在。 But if I try to refer to these methods within the java code on my Android device, I get the error messages: 但是如果我尝试在我的Android设备上的java代码中引用这些方法,我会收到错误消息:

“The method setNetworkName(String) is undefined for the type WifiP2pGroup”, and “方法setNetworkName(String)未定义类型WifiP2pGroup”,和

“The method setPassphrase(String) is undefined for the type WifiP2pGroup”. “WifiP2pGroup类型的方法setPassphrase(String)未定义”。

My question is: how can I access these hidden methods that exist within the Android 4.2.2 OS as public methods of theWifiP2pGroup? 我的问题是:我如何访问Android 4.2.2操作系统中存在的这些隐藏方法作为WifiP2pGroup的公共方法?

Is there any other way to set the SSID and passphrase apart from using these methods? 除了使用这些方法之外,还有其他方法可以设置SSID和密码吗?

Also, why did they choose to hide these methods, and would you know if they will be made available in a future release of Android? 此外,他们为什么选择隐藏这些方法,您是否知道它们是否会在未来的Android版本中提供? If so, which release? 如果是这样,哪个版本?

Thank you for any help that you can provide. 感谢您提供的任何帮助。

You can use reflection java. 你可以使用反射java。

Let us assume WifiP2pGroup group your current object. 让我们假设WifiP2pGroup组是您当前的对象。

Method setPassPhraseMethod=group.getClass().getMethod("setPassphrase", new Class[ {String.class}); 方法setPassPhraseMethod = group.getClass()。getMethod(“setPassphrase”,new Class [{String.class}); and now you invoke the method: 现在你调用方法:

setPassPhraseMethod.invoke(group, "yourNewPassPrhase"); setPassPhraseMethod.invoke(group,“yourNewPassPrhase”);

You can only use the APIs exposed in WifiP2pManager http://developer.android.com/reference/android/net/wifi/p2p/WifiP2pManager.html 您只能使用WifiP2pManager公开的API http://developer.android.com/reference/android/net/wifi/p2p/WifiP2pManager.html

The APIs you are referring to are internal APIs for recreating persistent groups. 您引用的API是用于重新创建持久组的内部API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM