Code example for WifiP2pManager

Methods: addLocalServiceinitialize

        return Service.START_NOT_STICKY;
    public void register(){ 
        mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
        mChannel = mManager.initialize(this, getMainLooper(), null);
        Map record = new HashMap();
        record.put("listenport", String.valueOf(0));
        record.put("buddyname", "John Doe" + (int) (Math.random() * 1000));
        record.put("available", "visible");
        // Service information.  Pass it an instance name, service type 
        // _protocol._transportlayer , and the map containing 
        // information other devices will want once they connect to this one. 
        WifiP2pDnsSdServiceInfo serviceInfo =
                WifiP2pDnsSdServiceInfo.newInstance("_nebula", "_ftp._tcp", record);
        // Add the local service, sending the service info, network channel, 
        // and listener that will be used to indicate success or failure of 
        // the request. 
        mManager.addLocalService(mChannel, serviceInfo, new WifiP2pManager.ActionListener() {
            public void onSuccess() { 
                // Command successful! Code isn't necessarily needed here, 
                // Unless you want to update the UI or add logging statements. 
Contextual code suggestions in your IDE  Get Codota for Java