how to solve discovering other device via Wi-Fi (android API)?

后端 未结 2 1487
时光取名叫无心
时光取名叫无心 2020-12-04 03:09

recently I follow the steps given from Developer.Android.Com

But it seems i have a few luck over there. I tried to discover the available peers nearby, put \'em into

相关标签:
2条回答
  • 2020-12-04 03:32

    I guess you did't add PeerListListener to your activity. so it won't reply.

    you can try to implement PeerListListener in your activity

    public class Chat1Activity extends Activity implements WifiP2pManager.PeerListListener
    

    and override onPeerAvailable method in your activity

     @Override
      public void onPeersAvailable(WifiP2pDeviceList peers) {
    
       //put your code here
    
      }
    

    and change requestPeers method in your Receiver

     if (mManager != null) {
                mManager.requestPeers(mChannel, mActivity);
     }
    

    Hope this help!!

    0 讨论(0)
  • 2020-12-04 03:45

    Have you check whether your device support Wifi Direct? Having a rom > 4.0 does not means it has wifi direct hardware support. Try to check that with PackageManager's API: http://developer.android.com/reference/android/content/pm/PackageManager.html#hasSystemFeature(java.lang.String)

    0 讨论(0)
提交回复
热议问题