I am developing a simple WiFi Direct-based application for Android that should connect two devices. To do this, I need to call función onPeersAvailable (myPeerListListener), but I do not know how to do this.
There are two elements in my application:
1-core activity:
package android.nacho.WifiDirect; import android.net.wifi.p2p.WifiP2pManager.Channel; import android.net.wifi.p2p.WifiP2pManager; import android.os.Bundle; import android.app.Activity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class WifiDirect extends Activity { WifiP2pManager mManager; Channel mChannel; BroadcastReceiver mReceiver; IntentFilter mIntentFilter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_wifi_direct);
2 BroadcastReceiver Class:
package android.nacho.WifiDirect; import android.net.wifi.p2p.WifiP2pManager.Channel; import android.net.wifi.p2p.WifiP2pManager.PeerListListener; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.wifi.p2p.WifiP2pManager; import android.widget.Toast; public class WiFiBroadcastReceiver extends BroadcastReceiver { private WifiP2pManager manager; private Channel channel; private WifiDirect activity; private PeerListListener myPeerListListener;
Until now, my code was supposed to detect peers around the device on which the application is running, and this identifier should be stored in the variable myPeerListListener . All this happens in the second intention of the BroadcastReceiver method called OnReceiv (), calling:
manager.requestPeers(channel, myPeerListListener);
Now I want to manipulate this list. Therefore, following the API information, it should call requestPeers, you can see the API here:
http://developer.android.com/guide/topics/connectivity/wifip2p.html
* Peer Detection Section
So, I tried to write below the call:
manager.onPeersAvailable(myPeerListListener);
but I get this error:
OnPeersAvailable method (WifiP2pManager.PeerListListener) undefined for type WifiP2pManager
Can someone tell me how I can properly send the PeerListListener function to the main action?
Thanks so much for your time.