user2301281
user2301281

Reputation: 787

how to set interface device name of wifi direct

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.

Upvotes: 1

Views: 1556

Answers (2)

Anuj Sharma
Anuj Sharma

Reputation: 4324

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();
        }
    }

Upvotes: 4

Ziad Halabi
Ziad Halabi

Reputation: 866

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.

Upvotes: 1

Related Questions