Android: How to get current device WiFi-direct name

前端 未结 3 1626
情深已故
情深已故 2021-01-04 13:53

In a P2P setting, I understand how to get another device\'s name, but how do I get my own device\'s name? (the one displayed in WiFi-direct under settings).

I have c

3条回答
  •  日久生厌
    2021-01-04 14:39

    After you turn on wifi on your device, it is send a WIFI_P2P_THIS_DEVICE_CHANGED_ACTION broadcast. You can catch this with a broadcast receiver and you can get a WifiP2pDevice object, that is your device.

     @Override
     public void onReceive(Context context, Intent intent) {
         WifiP2pDevice device = intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
         String thisDeviceName = device.deviceName;
     }
    

提交回复
热议问题