Java 类android.net.wifi.p2p.WifiP2pManager.DnsSdServiceResponseListener 实例源码

项目:servicediscoverypg    文件:WifiDirectManager.java   
private void setupDnsSdResponseListeners(final DnsSdResponseListener listener) {

    /*
        * Register listeners for DNS-SD services. These are callbacks invoked
        * by the system when a service is actually discovered.
        */
    manager.setDnsSdResponseListeners(channel, 
            new DnsSdServiceResponseListener() {

        public void onDnsSdServiceAvailable(String instanceName,
                String registrationType, WifiP2pDevice srcDevice) {

            listener.onServiceAvailable(instanceName, registrationType, srcDevice);
        }
    }, new DnsSdTxtRecordListener() {

        public void onDnsSdTxtRecordAvailable(
                String fullDomainName, Map<String, String> record,
                WifiP2pDevice device) {

            listener.onTxtRecordAvailable(fullDomainName, record, device);
        }
    });
}
项目:Audio-based-probing-of-the-environment    文件:WifiClient.java   
private void launchServiceListner(){
    Log.d(TAG, "Launching ServiceListner");
    manager.setDnsSdResponseListeners(channel,
            new DnsSdServiceResponseListener() {
            @Override
            public void onDnsSdServiceAvailable(String instanceName, String registrationType,WifiP2pDevice srcDevice) {
                Log.d(TAG, "ServiceAvailable " + instanceName);
                // A service has been discovered. check if this is the service we are searching for
                if (instanceName.equalsIgnoreCase(SERVER_SERVICE_INSTANCE)) {
                        //store the data in a service instance
                        WifiClientP2pService p2pservice = new WifiClientP2pService();   //class to store service object
                        p2pservice.setDevice(srcDevice);
                        p2pservice.setInstanceName(instanceName);
                        p2pservice.setServiceRegistrationType(registrationType);
                        Log.d("WifisrvListner", "WifiService: "+ p2pservice.getInstanceName()+" from: "+p2pservice.getDevice());
                        Log.d("WifisrvListner","deviceAddress: "+p2pservice.getDevice().deviceAddress);
                        Log.d("WifisrvListner","deviceName: "+p2pservice.getDevice().deviceName);
                        /***auto device list***/
                        Log.d("WifisrvListner","adding device in list ");
                        addDevice(p2pservice.getDevice().deviceAddress, p2pservice);        //add device to the MAP1
                        /***auto device list***/
                        //connectP2p();                             //connect to the device running server service
                }
            }
            }, new DnsSdTxtRecordListener() {
                @Override
                public void onDnsSdTxtRecordAvailable(String fullDomain, Map<String, String> record, WifiP2pDevice device) {
                    Log.d("WifiTxtListner", "DnsSdTxtRecord available -"+device.deviceAddress);
                    Log.d("WifiTxtListner", "DnsSdTxtRecord String -"+record.get(TXTRECORD_SERVER_ANDROIDID));    
                    /***auto device list***/
                    if(record.get(TXTRECORD_SERVER_ANDROIDID) != null){
                            addDeviceName(device.deviceAddress, record.get(TXTRECORD_SERVER_ANDROIDID)); //add device to the MAP2
                    }
                    /***auto device list***/

                }
            });   
}
项目:dissertation-project    文件:WifiDirectSdHelper.java   
private void initialiseDnsListener() {
    mDnsListener = new DnsSdServiceResponseListener() {

        @Override
        public void onDnsSdServiceAvailable(String instanceName,
                String registrationType, WifiP2pDevice srcDevice) {

            // A service has been discovered. Is this our app?

            if (instanceName.equalsIgnoreCase(SERVICE_INSTANCE)) {
                Log.d(TAG, "onBonjourServiceAvailable " + instanceName);
            }
        }
    };
}
项目:gilgamesh    文件:WifiController.java   
private void discoverWifiService() {
    DnsSdTxtRecordListener txtListener = new DnsSdTxtRecordListener() {
        @Override
        /* Callback includes:
         * fullDomain: full domain name: e.g "printer._ipp._tcp.local."
         * record: TXT record dta as a map of key/value pairs.
         * device: The device running the advertised service.
         */

        public void onDnsSdTxtRecordAvailable(String fullDomain, Map record, WifiP2pDevice device) {

                String status = (String)record.get("status");

                Log.d(TAG,"got status from wifi DNS: " + device.deviceAddress + " (" + fullDomain + ") " + status);
                mService.processInboundMessage(device.deviceAddress,status,false);
            }

        };

        DnsSdServiceResponseListener servListener = new DnsSdServiceResponseListener() {
            @Override
            public void onDnsSdServiceAvailable(String instanceName, String registrationType,
                    WifiP2pDevice resourceType) {
                Log.d(TAG,"SD service available!");
            }
        };

        mWifiManager.setDnsSdResponseListeners(mWifiChannel, servListener, txtListener);

        mWifiManager.discoverServices(mWifiChannel, new ActionListener() {

            @Override
            public void onSuccess() {
                // Success!
                Log.d(TAG, "discover services!");
            }

            @Override
            public void onFailure(int code) {
                // Command failed.  Check for P2P_UNSUPPORTED, ERROR, or BUSY
                if (code == WifiP2pManager.P2P_UNSUPPORTED) {
                    Log.d(TAG, "P2P isn't supported on this device.");
                    mWifiEnabled = false;
                }
            }
        });

}