Example usage for android.net.wifi WifiManager createMulticastLock

List of usage examples for android.net.wifi WifiManager createMulticastLock

Introduction

In this page you can find the example usage for android.net.wifi WifiManager createMulticastLock.

Prototype

public MulticastLock createMulticastLock(String tag) 

Source Link

Document

Create a new MulticastLock

Usage

From source file:org.mythtv.client.ui.MainMenuFragment.java

/**
 * @throws IOException/*ww w.jav a  2 s.  c  om*/
 */
private void startProbe() throws IOException {
    Log.v(TAG, "startProbe : enter");

    if (zeroConf != null) {
        stopProbe();
    }

    // figure out our wifi address, otherwise bail
    WifiManager wifi = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);

    WifiInfo wifiinfo = wifi.getConnectionInfo();
    int intaddr = wifiinfo.getIpAddress();

    byte[] byteaddr = new byte[] { (byte) (intaddr & 0xff), (byte) (intaddr >> 8 & 0xff),
            (byte) (intaddr >> 16 & 0xff), (byte) (intaddr >> 24 & 0xff) };
    InetAddress addr = InetAddress.getByAddress(byteaddr);
    Log.d(TAG, "startProbe : wifi address=" + addr.toString());

    // start multicast lock
    mLock = wifi.createMulticastLock("mythtv_lock");
    mLock.setReferenceCounted(true);
    mLock.acquire();

    zeroConf = JmDNS.create(addr, HOSTNAME);
    zeroConf.addServiceListener(MYTHTV_FRONTEND_TYPE, this);

    Log.v(TAG, "startProbe : exit");
}

From source file:org.deviceconnect.android.deviceplugin.irkit.IRKitManager.java

/**
 * ?./*from w  ww.j  a  va 2 s  .c  o  m*/
 * 
 * @param context 
 */
public synchronized void startDetection(final ContextWrapper context) {

    if (isDetecting()) {
        return;
    }

    mIsDetecting = true;
    init(context);

    WifiManager wifi = getWifiManager(context);
    mMultiLock = wifi.createMulticastLock(MULTI_CAST_LOCK_TAG);
    mMultiLock.setReferenceCounted(true);
    mMultiLock.acquire();

    WifiInfo info = wifi.getConnectionInfo();
    if (info != null) {
        mIpValue = info.getIpAddress();
    } else {
        mIpValue = 0;
    }

    new Thread(new Runnable() {

        @Override
        public void run() {
            synchronized (INSTANCE) {
                try {
                    if (mDNS != null || mIpValue == 0) {
                        mIsDetecting = false;
                        return;
                    }
                    InetAddress ia = parseIPAddress(mIpValue);
                    if (ia == null) {
                        mIsDetecting = false;
                        return;
                    }

                    mDNS = JmDNS.create(ia);
                    mDNS.addServiceListener(SERVICE_TYPE, mServiceListener);
                    mIsDetecting = true;

                    if (BuildConfig.DEBUG) {
                        Log.d(TAG, "start detection.");
                    }

                } catch (IOException e) {
                    if (BuildConfig.DEBUG) {
                        e.printStackTrace();
                    }
                    mIsDetecting = false;
                    mDNS = null;
                }
            }
        }
    }).start();
}

From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java

/**
 * mDNS?.//from w  ww  .j a va 2s  .c om
 * 
 */
public void searchDeviceByBonjour() {

    // cache?false????
    // ?,???????, Wifi?Broadcast????
    new Thread(new Runnable() {
        public void run() {

            services = new ArrayList<Bundle>();

            android.net.wifi.WifiManager wifi = (android.net.wifi.WifiManager) getSystemService(
                    android.content.Context.WIFI_SERVICE);
            WifiManager.MulticastLock lock = wifi.createMulticastLock("deviceplugin.host");
            lock.setReferenceCounted(true);
            lock.acquire();
        }
    }).start();

}

From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java

/**
 * mDNS??????./*from  www.j a  va  2  s  . c  o  m*/
 * 
 */
public void invokeDeviceByBonjour() {

    // cache?false????
    // ?,???????, Wifi?Broadcast????
    new Thread(new Runnable() {
        public void run() {

            services = new ArrayList<Bundle>();

            android.net.wifi.WifiManager wifi = (android.net.wifi.WifiManager) getSystemService(
                    android.content.Context.WIFI_SERVICE);
            WifiManager.MulticastLock lock = wifi.createMulticastLock("deviceplugin.host");
            lock.setReferenceCounted(true);
            lock.acquire();
        }
    }).start();

}

From source file:org.geometerplus.fbreader.plugin.local_opds_scanner.ScanLocalNetworkActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    setContentView(R.layout.scan_local_network);

    setListAdapter(new ItemAdapter());

    setTitle(R.string.scan_local_network_window_title);

    final View buttonView = findViewById(R.id.scan_local_network_buttons);

    final Button cancelButton = (Button) buttonView.findViewById(R.id.cancel_button);
    cancelButton.setText(R.string.button_cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            finish();/* ww w.  j a  v a  2  s  . c o m*/
        }
    });

    final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    final int state = wifiManager.getWifiState();
    if (state != WifiManager.WIFI_STATE_ENABLED && state != WifiManager.WIFI_STATE_ENABLING) {
        setTitle(R.string.wifi_is_turned_off);
        final View listView = findViewById(android.R.id.list);
        final TextView errorView = (TextView) findViewById(R.id.scan_local_network_error);
        listView.setVisibility(View.GONE);
        errorView.setVisibility(View.VISIBLE);
        errorView.setText(R.string.turn_wifi_on);

        final Button turnOnButton = (Button) buttonView.findViewById(R.id.ok_button);
        turnOnButton.setText(R.string.button_turn_on);
        turnOnButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                wifiManager.setWifiEnabled(true);
                finish();
            }
        });

        myLock = null;
    } else {
        final Button rescanButton = (Button) buttonView.findViewById(R.id.ok_button);
        rescanButton.setText(R.string.button_rescan);
        rescanButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                runOnUiThread(new Runnable() {
                    public void run() {
                        clear();
                        scan();
                    }
                });
            }
        });

        myLock = wifiManager.createMulticastLock("FBReader_lock");
        myLock.setReferenceCounted(true);
        myLock.acquire();

        scan();
    }
}