Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create a WifiP2pManager instance
- WifiP2pManager manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
- // Create a WifiP2pManager.Channel instance
- WifiP2pManager.Channel channel = manager.initialize(this, getMainLooper(), null);
- // Discover nearby devices
- manager.discoverPeers(channel, new WifiP2pManager.ActionListener() {
- @Override
- public void onSuccess() {
- // Peers discovered successfully
- }
- @Override
- public void onFailure(int reasonCode) {
- // Failed to discover peers
- }
- });
- // Connect to a specific device
- WifiP2pConfig config = new WifiP2pConfig();
- config.deviceAddress = "device_mac_address";
- manager.connect(channel, config, new WifiP2pManager.ActionListener() {
- @Override
- public void onSuccess() {
- // Connection successful
- }
- @Override
- public void onFailure(int reasonCode) {
- // Connection failed
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement