user3167366
user3167366

Reputation: 41

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. My Android (4.2.2) device is configured as the group owner. 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.

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. 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.

If you look through the android code for the WifiP2pGroup, listed at:

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. But if I try to refer to these methods within the java code on my Android device, I get the error messages:

“The method setNetworkName(String) is undefined for the type WifiP2pGroup”, and

“The method setPassphrase(String) is undefined for the type WifiP2pGroup”.

My question is: how can I access these hidden methods that exist within the Android 4.2.2 OS as public methods of theWifiP2pGroup?

Is there any other way to set the SSID and passphrase apart from using these methods?

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? If so, which release?

Thank you for any help that you can provide.

Upvotes: 4

Views: 2732

Answers (2)

amine
amine

Reputation: 131

You can use reflection java.

Let us assume WifiP2pGroup group your current object.

Method setPassPhraseMethod=group.getClass().getMethod("setPassphrase", new Class[ {String.class}); and now you invoke the method:

setPassPhraseMethod.invoke(group, "yourNewPassPrhase");

Upvotes: 3

vishalm
vishalm

Reputation: 477

You can only use the APIs exposed in WifiP2pManager http://developer.android.com/reference/android/net/wifi/p2p/WifiP2pManager.html

The APIs you are referring to are internal APIs for recreating persistent groups.

Upvotes: 1

Related Questions