List of usage examples for android.net.wifi.p2p.nsd WifiP2pDnsSdServiceRequest newInstance
public static WifiP2pDnsSdServiceRequest newInstance()
From source file:it.polimi.deib.p2pchat.discovery.chatmessages.waitingtosend.discovery.MainActivity.java
/** * Method to discover services and put the results * in {@link ServiceList}./* w w w .j a v a 2 s. c o m*/ * This method updates also the discovery menu item. */ private void discoverService() { ServiceList.getInstance().clear(); toolbar.getMenu().findItem(R.id.discovery) .setIcon(getResources().getDrawable(R.drawable.ic_action_search_searching)); /* * Register listeners for DNS-SD services. These are callbacks invoked * by the system when a service is actually discovered. */ manager.setDnsSdResponseListeners(channel, new CustomDnsServiceResponseListener(), new CustomDnsSdTxtRecordListener()); // After attaching listeners, create a service request and initiate // discovery. serviceRequest = WifiP2pDnsSdServiceRequest.newInstance(); //inititiates discovery manager.addServiceRequest(channel, serviceRequest, new CustomizableActionListener(MainActivity.this, "discoverService", "Added service discovery request", null, "Failed adding service discovery request", "Failed adding service discovery request")); //starts services disovery manager.discoverServices(channel, new ActionListener() { @Override public void onSuccess() { Log.d(TAG, "Service discovery initiated"); Toast.makeText(MainActivity.this, "Service discovery initiated", Toast.LENGTH_SHORT).show(); blockForcedDiscoveryInBroadcastReceiver = false; } @Override public void onFailure(int reason) { Log.d(TAG, "Service discovery failed"); Toast.makeText(MainActivity.this, "Service discovery failed, " + reason, Toast.LENGTH_SHORT).show(); } }); }