how to set interface device name of wifi direct

a 夏天 提交于 2019-12-23 04:47:34

问题


I have the similar question with this post Android WiFi Direct device details However, it seem din't get any solution from that post.

Is it any method can used to set the wifi-direct name that similar with function of "setName()" or "setServiceName" in bluetoohAdapter & NsdServiceInfo.


回答1:


You can rename the device WiFi Direct name using reflection. Check the solution here: Android rename device's name for wifi-direct

Additionally, there is a file called p2p_supplicant.conf in the /data/misc/wifi/p2p_supplicant.conf that contains a field where the WiFi Direct name is specified. You can edit it using my answer on with a slight adjustment: editing a value in the file p2p_supplicant.conf which is located on /root/data/misc/wifi/p2p_supplicant.conf

Just a note that you can manually change the name of the WiFi Direct device on the phone without the need for an App. There is a rename device option in WiFi->Wifi Direct on Android phones.

Hope this helps. Let me know if you have any questions.




回答2:


I know this is late. But you can try this. Here you have to pass WifiP2pManager instance alogn with WifiP2pManager.Channel instance and your custom name that you want to set.

This worked for me, Hope it will help you too.

    /*
    Set WifiP2p Device Name
     */
    public void setDeviceName(WifiP2pManager manager, WifiP2pManager.Channel channel, String deviceName){
        //set device name programatically
        try {
            Class[] paramTypes = new Class[3];
            paramTypes[0] = WifiP2pManager.Channel.class;
            paramTypes[1] = String.class;
            paramTypes[2] = WifiP2pManager.ActionListener.class;
            Method setDeviceName = manager.getClass().getMethod(
                    "setDeviceName", paramTypes);
            setDeviceName.setAccessible(true);

            Object arglist[] = new Object[3];
            arglist[0] = channel;
            arglist[1] = deviceName;
            arglist[2] = new WifiP2pManager.ActionListener() {

                @Override
                public void onSuccess() {
                }

                @Override
                public void onFailure(int reason) {
                }
            };

            setDeviceName.invoke(manager, arglist);

        }
        catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }


来源:https://stackoverflow.com/questions/30170537/how-to-set-interface-device-name-of-wifi-direct

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