How to get the deviceName of my device using wifi p2p

只谈情不闲聊 提交于 2019-12-25 06:44:57

问题


I'm developing an app based on Google's wifi p2p API and I would like to get the name of the device I'm using (not the peers) but the only way I found to retrieve the name is in case I change it by using something like this:

if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {  
          // this device details has changed(name, connected, etc)
          mApp.mThisDevice = (WifiP2pDevice) intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);

          mApp.mDeviceName = mApp.mThisDevice.deviceName;
          PTPLog.d(TAG, "processIntent: WIFI_P2P_THIS_DEVICE_CHANGED_ACTION " + mApp.mThisDevice.deviceName);
          if( mApp.mHomeActivity != null ){
              mApp.mHomeActivity.updateThisDevice(mApp.mThisDevice);
          }
      }

But I don't want that (to wait until a change), I want to know my own name from the beginning, in order to show it when I just open the app. Is this possible?


回答1:


If Wi-Fi is enabled and you register P2P and everything on load, then the device name should be available right away when that intent fires. If Wi-Fi is disabled, then you would have to wait for it to be enabled if you want to get the device name from WifiP2pManager. That's the only way I know how to get the name.




回答2:


The only way I see, is using reflection to change the device name and then using your code to get the original device name, after that you can set the device name back to the original.



来源:https://stackoverflow.com/questions/37942651/how-to-get-the-devicename-of-my-device-using-wifi-p2p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!