Android NsdManager - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android NsdManager class.

This code example shows how to use the following methods: setEnabled
 
    public boolean onPreferenceChange(Preference preference, Object value) {
 
        final boolean desiredState = (Boolean) value;
        mCheckbox.setEnabled(false);
        mNsdManager.setEnabled(desiredState);
        return false; 
    } 
 
    private void handleNsdStateChanged(int newState) {
        switch (newState) {
            case NsdManager.NSD_STATE_DISABLED:
                mCheckbox.setChecked(false);
                mCheckbox.setEnabled(true);
                break; 
            case NsdManager.NSD_STATE_ENABLED:
                mCheckbox.setChecked(true);
                mCheckbox.setEnabled(true);
                break; 
        } 
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: stopServiceDiscovery
        mNsdManager.discoverServices(
                SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, mDiscoveryListener);
    } 
     
    public void stopDiscovery() { 
        mNsdManager.stopServiceDiscovery(mDiscoveryListener);
    } 
 
    public NsdServiceInfo getChosenServiceInfo() {
        return mService;
    } 
     
    public void tearDown() { 
        mNsdManager.unregisterService(mRegistrationListener);
    } 
} 
Full Snippet Info
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: registerService
     * Register service to mDNS/DNS-SD. 
     */ 
    void registerService() { 
        NsdServiceInfo serviceInfo = allocateServiceInfo();
        int protocolType = NsdManager.PROTOCOL_DNS_SD;
        nsdManager.registerService(serviceInfo, protocolType, registrationListener);
    } 
 
    /** 
     * Unregister service from mDNS/DNS-SD. 
     */ 
    void unregisterService() { 
        if (regstrationListenerRegistered)
            nsdManager.unregisterService(registrationListener);
    } 
 
    // Activity's lifecycle methods. 
 
    @Override 
    public void onCreate(Bundle savedInstanceState) {
Full Snippet Info
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: stopServiceDiscovery
			@Override 
			public void onStartDiscoveryFailed(String serviceType, int errorCode) {
				Log.d(TAG,
						"DiscoveryListener#onStartDiscoveryFailed errorCode=" 
								+ errorCode);
				mNsdManager.stopServiceDiscovery(this);
			} 
 
			@Override 
			public void onServiceFound(final NsdServiceInfo service) {
				Log.d(TAG, "DiscoveryListener#onServiceFound service="
						+ service);
				if (!service.getServiceType().equals(sServiceType)) {
					Log.d(TAG,
							"Unknown Service Type: " + service.getServiceType());
				} else if (service.getServiceName().startsWith(mServiceName)) {
					// 少し乱暴だけど、同一マシンが "わかめ (2)" とかいって複数検出されるので。 
					Log.d(TAG, "Same machine: " + mServiceName);
				} else { 
					Log.d(TAG, "New service found: " + mServiceList.size());
Full Snippet Info
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: stopServiceDiscovery
		} 
 
		@Override 
		public void onStartDiscoveryFailed(String serviceType, int errorCode) {
			Log.e(TAG, "Discovery failed: Error code:" + errorCode);
			_NsdManager.stopServiceDiscovery(this);
			 
		} 
 
		@Override 
		public void onStopDiscoveryFailed(String serviceType, int errorCode) {
			Log.e(TAG, "Discovery failed: Error code:" + errorCode);
			_NsdManager.stopServiceDiscovery(this);
			 
		} 
		 
	} 
 
	 
 
Full Snippet Info
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: stopServiceDiscovery
            } 
 
            @Override 
            public void onStartDiscoveryFailed(String serviceType, int errorCode) {
                Log.e(TAG, "Discovery failed: Error code:" + errorCode);
                mNsdManager.stopServiceDiscovery(this);
            } 
 
            @Override 
            public void onStopDiscoveryFailed(String serviceType, int errorCode) {
                Log.e(TAG, "Discovery failed: Error code:" + errorCode);
                mNsdManager.stopServiceDiscovery(this);
            } 
        }; 
    } 
 
    public void initializeResolveListener() { 
        mResolveListener = new NsdManager.ResolveListener() {
 
            @Override 
Full Snippet Info
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: unregisterService
	} 
 
	@Override 
	public void onDestroy() { 
		running = false;
		mNsdManager.unregisterService(mRegistrationListener);
		// mNsdManager.stopServiceDiscovery(mDiscoveryListener); 
		super.onDestroy(); 
	} 
 
	public static void destroy() { 
		try { 
			running = false;
			Log.i(TAG, "Stopping NSD Service");
			mNsdManager.unregisterService(mRegistrationListener);
		} catch(Exception e) {
			Log.e(TAG, "Error: NSD service stopped before being registered");
		} 
	} 
 
Full Snippet Info
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: registerService
			return; 
		NsdServiceInfo serviceInfo = new NsdServiceInfo();
		serviceInfo.setPort(port);
		serviceInfo.setServiceName(myServiceName);
		serviceInfo.setServiceType(SERVICE_TYPE);
		nsdMgr.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD,
				registrationListener);
	} 
	 
	private void unregisterService() { 
		if (isRegistered) {
			Log.i(TAG, "unregister ShareService");
			nsdMgr.unregisterService(registrationListener);
		} 
	} 
 
	void updateExternalStorageState() { 
		String state = Environment.getExternalStorageState();
		if (Environment.MEDIA_MOUNTED.equals(state)) {
			externalStorageAvailable = true;
Full Snippet Info
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: stopServiceDiscovery
            mServiceListener);
    } 
     
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    private void stopListeningForService() { 
        mNsdManager.stopServiceDiscovery(mServiceListener);
    } 
     
    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	// Check what activity has finished. Depending on that, another activity  
    	// is called or the app closes 
     	if (requestCode == ID_CONNECT_DIALOG) {
    		if (resultCode == Activity.RESULT_CANCELED) {
        		finish();
        	} 
        	if (resultCode == RESULT_CONNECT) {
        		startPlayerDialog(); 
        	} 
        	return; 
Full Snippet Info
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: resolveService
                if (!serviceInfo.getServiceType().equals(SERVICE_TYPE)) {
                    logMsg("Unknown Service Type: " + serviceInfo.getServiceType());
                } else if (serviceInfo.getServiceName().equals(mServiceName)) {
                    logMsg("Same machine: " + mServiceName);
                } else if (serviceInfo.getServiceName().contains(mServiceName)) {
                    mNsdManager.resolveService(serviceInfo, mResolveListener);
                } 
            } 
 
            @Override 
            public void onServiceLost(NsdServiceInfo serviceInfo) {
                logMsg("service lost."); 
                if (serviceInfo == mService) {
                    mService = null;
                } 
            } 
        }; 
    } 
 
    public void logMsg(String str) {
Full Snippet Info
4
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Android NsdManager Methods: