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:com.syncedsynapse.kore2.ui.hosts.AddHostFragmentZeroconf.java

/**
 * Starts the service discovery, setting up the UI accordingly
 *//*from   ww w.  j ava 2  s. c o m*/
public void startSearching() {
    LogUtils.LOGD(TAG, "Starting service discovery...");
    searchCancelled = false;
    final Handler handler = new Handler();
    final Thread searchThread = new Thread(new Runnable() {
        @Override
        public void run() {
            WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
            WifiManager.MulticastLock multicastLock = null;
            try {
                // Get wifi ip address
                int wifiIpAddress = wifiManager.getConnectionInfo().getIpAddress();
                InetAddress wifiInetAddress = NetUtils.intToInetAddress(wifiIpAddress);

                // Acquire multicast lock
                multicastLock = wifiManager.createMulticastLock("kore2.multicastlock");
                multicastLock.setReferenceCounted(false);
                multicastLock.acquire();

                JmDNS jmDns = (wifiInetAddress != null) ? JmDNS.create(wifiInetAddress) : JmDNS.create();

                // Get the json rpc service list
                final ServiceInfo[] serviceInfos = jmDns.list(MDNS_XBMC_SERVICENAME, DISCOVERY_TIMEOUT);

                synchronized (lock) {
                    // If the user didn't cancel the search, and we are sill in the activity
                    if (!searchCancelled && isAdded()) {
                        handler.post(new Runnable() {
                            @Override
                            public void run() {
                                if ((serviceInfos == null) || (serviceInfos.length == 0)) {
                                    noHostFound();
                                } else {
                                    foundHosts(serviceInfos);
                                }
                            }
                        });
                    }
                }
            } catch (IOException e) {
                LogUtils.LOGD(TAG, "Got an IO Exception", e);
            } finally {
                if (multicastLock != null)
                    multicastLock.release();
            }
        }
    });

    titleTextView.setText(R.string.searching);
    messageTextView.setText(Html.fromHtml(getString(R.string.wizard_search_message)));
    messageTextView.setMovementMethod(LinkMovementMethod.getInstance());

    progressBar.setVisibility(View.VISIBLE);
    hostListGridView.setVisibility(View.GONE);

    // Setup buttons
    nextButton.setVisibility(View.INVISIBLE);
    previousButton.setVisibility(View.VISIBLE);
    previousButton.setText(android.R.string.cancel);
    previousButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            synchronized (lock) {
                searchCancelled = true;
                noHostFound();
            }
        }
    });

    searchThread.start();
}

From source file:org.xbmc.kore.ui.hosts.AddHostFragmentZeroconf.java

/**
 * Starts the service discovery, setting up the UI accordingly
 */// w  w  w .j  a va2  s  . c o m
public void startSearching() {
    if (!isNetworkConnected()) {
        noNetworkConnection();
        return;
    }

    LogUtils.LOGD(TAG, "Starting service discovery...");
    searchCancelled = false;
    final Handler handler = new Handler();
    final Thread searchThread = new Thread(new Runnable() {
        @Override
        public void run() {
            WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);

            WifiManager.MulticastLock multicastLock = null;
            try {
                // Get wifi ip address
                int wifiIpAddress = wifiManager.getConnectionInfo().getIpAddress();
                InetAddress wifiInetAddress = NetUtils.intToInetAddress(wifiIpAddress);

                // Acquire multicast lock
                multicastLock = wifiManager.createMulticastLock("kore2.multicastlock");
                multicastLock.setReferenceCounted(false);
                multicastLock.acquire();

                JmDNS jmDns = (wifiInetAddress != null) ? JmDNS.create(wifiInetAddress) : JmDNS.create();

                // Get the json rpc service list
                final ServiceInfo[] serviceInfos = jmDns.list(MDNS_XBMC_SERVICENAME, DISCOVERY_TIMEOUT);

                synchronized (lock) {
                    // If the user didn't cancel the search, and we are sill in the activity
                    if (!searchCancelled && isAdded()) {
                        handler.post(new Runnable() {
                            @Override
                            public void run() {
                                if ((serviceInfos == null) || (serviceInfos.length == 0)) {
                                    noHostFound();
                                } else {
                                    foundHosts(serviceInfos);
                                }
                            }
                        });
                    }
                }
            } catch (IOException e) {
                LogUtils.LOGD(TAG, "Got an IO Exception", e);
            } finally {
                if (multicastLock != null)
                    multicastLock.release();
            }
        }
    });

    titleTextView.setText(R.string.searching);
    messageTextView.setText(Html.fromHtml(getString(R.string.wizard_search_message)));
    messageTextView.setMovementMethod(LinkMovementMethod.getInstance());

    progressBar.setVisibility(View.VISIBLE);
    hostListGridView.setVisibility(View.GONE);

    // Setup buttons
    nextButton.setVisibility(View.INVISIBLE);
    previousButton.setVisibility(View.VISIBLE);
    previousButton.setText(android.R.string.cancel);
    previousButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            synchronized (lock) {
                searchCancelled = true;
                noHostFound();
            }
        }
    });

    searchThread.start();
}

From source file:com.hbm.devices.scan.ui.android.DeviceListFragment.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    /*//  w w w.j  a  v  a2  s . c  om
     * Probably a good idea to update UI only after this method was called.
     * Then we should have a complete view. In onDestroyView we can stop updating UI.
     * Probably a better idea is to start/stop updating UI in onResume/onPause.
     * Has to be clarified if these methods are called when activity goes into background.
     */
    final ScanActivity activity = (ScanActivity) getActivity();
    final WifiManager wifi = (WifiManager) activity.getApplicationContext()
            .getSystemService(Context.WIFI_SERVICE);
    if (wifi == null) {
        final Toast failureToast = Toast.makeText(activity,
                activity.getString(R.string.could_not_get_wifimanager), Toast.LENGTH_SHORT);
        failureToast.show();
    } else {
        if (wifiLock == null || !wifiLock.isHeld()) {
            wifiLock = wifi.createWifiLock("wifi lock");
            wifiLock.acquire();
        }
        if (mcLock == null || !mcLock.isHeld()) {
            mcLock = wifi.createMulticastLock("multicast lock");
            mcLock.acquire();
        }
    }
    if (adapter.get() != null) {
        updateList();
    }

    prefUseFakeMessages = getString(R.string.pref_use_fake_messages);
    prefFakeMessageType = getString(R.string.pref_fake_message_type);
}

From source file:org.xbmc.kore.ui.sections.hosts.AddHostFragmentZeroconf.java

/**
 * Starts the service discovery, setting up the UI accordingly
 *///from  ww w .ja v  a 2  s  . c o m
public void startSearching() {
    if (!isNetworkConnected()) {
        noNetworkConnection();
        return;
    }

    LogUtils.LOGD(TAG, "Starting service discovery...");
    searchCancelled = false;
    final Handler handler = new Handler();
    final Thread searchThread = new Thread(new Runnable() {
        @Override
        public void run() {
            WifiManager wifiManager = (WifiManager) getActivity().getApplicationContext()
                    .getSystemService(Context.WIFI_SERVICE);

            WifiManager.MulticastLock multicastLock = null;
            try {
                // Get wifi ip address
                int wifiIpAddress = wifiManager.getConnectionInfo().getIpAddress();
                InetAddress wifiInetAddress = NetUtils.intToInetAddress(wifiIpAddress);

                // Acquire multicast lock
                multicastLock = wifiManager.createMulticastLock("kore2.multicastlock");
                multicastLock.setReferenceCounted(false);
                multicastLock.acquire();

                JmDNS jmDns = (wifiInetAddress != null) ? JmDNS.create(wifiInetAddress) : JmDNS.create();

                // Get the json rpc service list
                final ServiceInfo[] serviceInfos = jmDns.list(MDNS_XBMC_SERVICENAME, DISCOVERY_TIMEOUT);

                synchronized (lock) {
                    // If the user didn't cancel the search, and we are sill in the activity
                    if (!searchCancelled && isAdded()) {
                        handler.post(new Runnable() {
                            @Override
                            public void run() {
                                if ((serviceInfos == null) || (serviceInfos.length == 0)) {
                                    noHostFound();
                                } else {
                                    foundHosts(serviceInfos);
                                }
                            }
                        });
                    }
                }
            } catch (IOException e) {
                LogUtils.LOGD(TAG, "Got an IO Exception", e);
            } finally {
                if (multicastLock != null)
                    multicastLock.release();
            }
        }
    });

    titleTextView.setText(R.string.searching);
    messageTextView.setText(Html.fromHtml(getString(R.string.wizard_search_message)));
    messageTextView.setMovementMethod(LinkMovementMethod.getInstance());

    progressBar.setVisibility(View.VISIBLE);
    hostListGridView.setVisibility(View.GONE);

    // Setup buttons
    nextButton.setVisibility(View.INVISIBLE);
    previousButton.setVisibility(View.VISIBLE);
    previousButton.setText(android.R.string.cancel);
    previousButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            synchronized (lock) {
                searchCancelled = true;
                noHostFound();
            }
        }
    });

    searchThread.start();
}

From source file:com.connectsdk.discovery.DiscoveryManager.java

/**
 * Create a new instance of DiscoveryManager.
 * Direct use of this constructor is not recommended. In most cases,
 * you should use DiscoveryManager.getInstance() instead.
 *//*from  w  w  w.j a v a  2s. com*/
public DiscoveryManager(Context context, ConnectableDeviceStore connectableDeviceStore) {
    this.context = context;
    this.connectableDeviceStore = connectableDeviceStore;

    allDevices = new ConcurrentHashMap<String, ConnectableDevice>(8, 0.75f, 2);
    compatibleDevices = new ConcurrentHashMap<String, ConnectableDevice>(8, 0.75f, 2);

    deviceClasses = new ConcurrentHashMap<String, Class<? extends DeviceService>>(4, 0.75f, 2);
    discoveryProviders = new CopyOnWriteArrayList<DiscoveryProvider>();

    discoveryListeners = new CopyOnWriteArrayList<DiscoveryManagerListener>();

    WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    multicastLock = wifiMgr.createMulticastLock("Connect SDK");
    multicastLock.setReferenceCounted(true);

    capabilityFilters = new ArrayList<CapabilityFilter>();
    pairingLevel = PairingLevel.OFF;

    receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
                NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);

                switch (networkInfo.getState()) {
                case CONNECTED:
                    if (mSearching) {
                        for (DiscoveryProvider provider : discoveryProviders) {
                            provider.start();
                        }
                    }

                    break;

                case DISCONNECTED:
                    Log.w("Connect SDK", "Network connection is disconnected");

                    for (DiscoveryProvider provider : discoveryProviders) {
                        provider.reset();
                    }

                    allDevices.clear();

                    for (ConnectableDevice device : compatibleDevices.values()) {
                        handleDeviceLoss(device);
                    }
                    compatibleDevices.clear();

                    for (DiscoveryProvider provider : discoveryProviders) {
                        provider.stop();
                    }

                    break;

                case CONNECTING:
                    break;
                case DISCONNECTING:
                    break;
                case SUSPENDED:
                    break;
                case UNKNOWN:
                    break;
                }
            }
        }
    };

    registerBroadcastReceiver();
}

From source file:org.universAAL.android.services.MiddlewareService.java

@Override
public void onCreate() {
    // This is where MW is created as it is called once when service is instantiated. Make sure it runs forever.
    super.onCreate();
    Log.v(TAG, "Create");
    mPercentage = 0;//from  ww  w  .  ja  v  a2 s  .  c  om

    // Ongoing notification is mandatory after Android 4.0
    Intent notificationIntent = new Intent(this, HandlerActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            Intent.FLAG_ACTIVITY_NEW_TASK);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_notif)
            .setContentTitle(getString(R.string.notif_title)).setContentText(getString(R.string.notif_text))
            .setContentIntent(contentIntent).setPriority(NotificationCompat.PRIORITY_MIN);
    Notification notif = builder.build();
    notif.flags |= Notification.FLAG_NO_CLEAR;
    startForeground(ONGOING_NOTIFICATION, notif);

    //Load initial config through Config utility. Changing config requires restart the MW service to take effect.
    Config.load(getApplicationContext());
    // These properties must be set here, not from file
    System.setProperty("java.net.preferIPv4Stack", "true");
    System.setProperty("java.net.preferIPv6Stack", "false");
    System.setProperty("java.net.preferIPv4Addresses", "true");
    System.setProperty("java.net.preferIPv6Addresses", "false");
    System.setProperty("jgroups.use.jdk_logger ", "true");
    System.setProperty("net.slp.port", "5555");
    System.setProperty("org.universAAL.middleware.peer.is_coordinator",
            Boolean.toString(Config.isServiceCoord()));

    // This is for setting IP manually, just in case (set it everytime you
    // get a new IP). If not set, it seems it also works, but SLP keeps
    // working on multicast for a while after Wifi is turned off.
    // System.setProperty("net.slp.interfaces", "192.168.0.126");

    // This is for not blocking the sockets when reconnecting (check its
    // javadoc). Common sense would suggest to set it false, but it still
    // works without doing so.
    // System.setProperty("http.keepAlive", "false");

    // Google had the wonderful idea in Android 5.0 of not enabling WIFI
    // connection when it does not have internet access, and fall back to
    // data connection. So in 5.0 we have to deliberately request WIFI and
    // set it as the process connection when it "becomes" available. And
    // pray that WIFI is ON by the time we make our checks...
    if (Config.isWifiAllowed()) {
        requestLollipopWifi();
    }

    // Create (dont use yet) the multicast lock. Make it not counted: this app only uses one lock
    WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    mLock = wifi.createMulticastLock("uaal_multicast");
    mLock.setReferenceCounted(false);

    // Set the static platform of SLP (for logging and stuff). Do it here cause its static (!)
    SLPCore.platform = AndroidContext.THE_CONTEXT;
    // Start the MW! Put all the above inside thread too? Cmon, its fast! Also, notification must be there
    new Thread(new Runnable() {
        public void run() {
            // Start the MW in onCreate makes sure it is running before
            // handling any intents. The only problem is when stopping the
            // MW and an intent comes... TODO
            addPercent(1);
            mCurrentWIFI = checkWifi();//Set the initial status of WIFI
            // 1. Stop-start the connector modules. Use jSLP only IF WIFI enabled, and WIFI==WIFI_HOME or WIFI_NOT_SET
            if (Config.isWifiAllowed()
                    && (mCurrentWIFI == AppConstants.WIFI_HOME || mCurrentWIFI == AppConstants.WIFI_NOTSET)) {
                restartConnector(true);
            } else {
                restartConnector(false);
            }
            // 2. Start the MW modules
            startMiddleware();
            // 3. Register the ontologies
            // It appears ont service does run in separate thread > race cond: AP ont may not be reg before handler
            // That is why I moved to a static method instead of ACTION_ONT_REG_ALL intent TODO retrofit OntologyService
            OntologyService.registerOntologies(MiddlewareService.this);
            addPercent(25);
            // 4. Start UI handler TODO start handler in last place
            if (Config.isUIHandler()) {
                startHandler();
            } else {
                addPercent(5);//startHandler() adds 5 when finished
            }
            // 5. Start GW IF WIFI==NOT_ON or WIFI==STRANGER (or if ALWAYS)
            if (isGWrequired()) {
                startGateway();
            }
            addPercent(10);
            // 6. Register the apps
            Intent scan = new Intent(AppConstants.ACTION_PCK_REG_ALL);
            scan.setClass(MiddlewareService.this, ScanService.class);
            startService(scan);
        }
    }, TAG_THREAD_CREATE).start();
    Log.v(TAG, "Created");
}

From source file:org.protocoderrunner.apprunner.api.PNetwork.java

@ProtocoderScript
@APIMethod(description = "Enable multicast networking", example = "")
@APIParam(params = { "boolean" })
public void setMulticast(boolean b) {
    WifiManager wifi = (WifiManager) a.get().getSystemService(Context.WIFI_SERVICE);
    if (wifi != null) {
        if (b) {//from  w  w  w. j av  a2 s  .c  om
            wifiLock = wifi.createMulticastLock("mylock");
            wifiLock.acquire();
        } else {
            wifiLock.release();
        }
    }
}

From source file:org.qeo.android.service.QeoService.java

@Override
public void onCreate() {
    // initialize QeoSuspendHelper singleton
    mQeoSuspendHelper = QeoSuspendHelper.getInstance(this);
    // don't do any calls to native here as this will init the native libraries on the UI thread!
    LOG.info("Creating service");
    if (mDestroyed) {
        throw new IllegalStateException("This service is already destroyed");
    }/*ww  w.j  a  v  a  2 s .  com*/

    // Init different version of the AIDL interfaces
    mQeoServiceImpl = new QeoServiceImpl(this);
    mBinderV1 = new QeoServiceV1(mQeoServiceImpl);

    // init ServiceApplication. Only really needed if the service is embedded, but won't do anything if running
    // standalone so it's not harm in calling it here.
    ServiceApplication.initServiceApp(getApplicationContext());

    mSettingsExternal = ServiceApplication.getProperties().getExternalSettings();
    mSettingsInternal = new ConfigurableSettings(this, ConfigurableSettings.FILE_QEO_PREFS, false);
    synchronized (this) {
        mHandler = new Handler(Looper.getMainLooper());
    }

    /* Uncomment the next line if you want to debug the Qeo service */
    // android.os.Debug.waitForDebugger();

    final WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    if (wifi != null) {
        // take multicast lock. Not required on all devices as some have
        // this by default enabled in their drivers.
        mMulticastLock = wifi.createMulticastLock("mQeo");
        mMulticastLock.acquire();
    }
    mOnNetworkConnectivityChanged = null;
}

From source file:com.example.zoetablet.BasicFragmentActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Set the orientation
    //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    //Shapes and Coredx DDS Initialization
    // magic to enable WiFi multicast to work on some android platforms:
    WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    mcastLock = wifi.createMulticastLock("Tablet");
    mcastLock.acquire();//from w w  w  . j  a v a 2  s. co  m

    //Tablet variables
    tablet = new Vector<TabletWriter>();

    // open CoreDX DDS license file:
    BufferedReader br = null;
    String license = new String("<");
    try {
        Log.i("Debug", "...Opening License");
        br = new BufferedReader(new InputStreamReader(this.getAssets().open("coredx_dds.lic")));
    } catch (IOException e) {
        Log.i("Debug", "...License did not open");
        Log.e("Tablet", e.getMessage());
    }
    if (br != null) {
        String ln;
        try {
            while ((ln = br.readLine()) != null) {
                license = new String(license + ln + "\n");
            }
        } catch (IOException e) {
            //  Log.e("Tablet", e.getMessage());
        }
    }
    license = new String(license + ">");
    Log.i("Tablet", "...License seems to be good");

    //Initialize Variables
    XVel = 1;
    YVel = 2;
    CompassDir = 3;
    GPS_LN = 4;
    GPS_LT = 5;
    Log_DDS = DateFormat.getDateTimeInstance().format(new Date());

    //For the Image, use current image display and 
    String fileName = "/storage/sdcard0/DCIM/no_video.jpg";
    Bitmap bmp;
    bmp = BitmapFactory.decodeFile(fileName);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 40, baos);
    buffer = baos.toByteArray();
    data_image_DDS = buffer;

    Log.i("Tablet", "Creating Subscriber");
    class TestDataReaderListener implements DataReaderListener {

        @Override
        public long get_nil_mask() {
            return 0;
        }

        @Override
        public void on_requested_deadline_missed(DataReader dr, RequestedDeadlineMissedStatus status) {
            System.out.println(" @@@@@@@@@@@     REQUESTED DEADLINE MISSED    @@@@@");
            System.out.println(" @@@@@@@@@@@                                  @@@@@");
            System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
        };

        @Override
        public void on_requested_incompatible_qos(DataReader dr, RequestedIncompatibleQosStatus status) {
            System.out.println(" @@@@@@@@@@@     REQUESTED INCOMPAT QOS    @@@@@@@@");
            System.out.println(" @@@@@@@@@@@        dr      = " + dr);
            System.out.println(" @@@@@@@@@@@                               @@@@@@@@");
            System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
        };

        @Override
        public void on_sample_rejected(DataReader dr, SampleRejectedStatus status) {
        };

        @Override
        public void on_liveliness_changed(DataReader dr, LivelinessChangedStatus status) {
            TopicDescription td = dr.get_topicdescription();
            System.out.println(" @@@@@@@@@@@     LIVELINESS CHANGED  " + td.get_name() + " @@@@@@@@@@");
        }

        @Override
        public void on_subscription_matched(DataReader dr, SubscriptionMatchedStatus status) {
            TopicDescription td = dr.get_topicdescription();
            System.out.println(" @@@@@@@@@@@     SUBSCRIPTION MATCHED    @@@@@@@@@@");
            System.out.println(
                    " @@@@@@@@@@@        topic   = " + td.get_name() + " (type: " + td.get_type_name() + ")");
            System.out.println(" @@@@@@@@@@@        current = " + status.get_current_count());
            System.out.println(" @@@@@@@@@@@                             @@@@@@@@@@");
            System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
        }

        @Override
        public void on_sample_lost(DataReader dr, SampleLostStatus status) {
            System.out.println(" @@@@@@@@@@@   SAMPLE LOST    @@@@@@@@@@");
        };

        @Override
        public void on_data_available(DataReader dr) {

            TopicDescription td = dr.get_topicdescription();
            dataDDSDataReader data_message = (dataDDSDataReader) dr;
            System.out.println(" @@@@@@@@@@@     DATA AVAILABLE          @@@@@@@@@@");
            System.out.println(
                    " @@@@@@@@@@@        topic = " + td.get_name() + " (type: " + td.get_type_name() + ")");

            samples = new dataDDSSeq();
            SampleInfoSeq si = new SampleInfoSeq();

            ReturnCode_t retval = data_message.take(samples, si, 100, coredxConstants.DDS_ANY_SAMPLE_STATE,
                    coredxConstants.DDS_ANY_VIEW_STATE, coredxConstants.DDS_ANY_INSTANCE_STATE);
            System.out.println(" @@@@@@@@@@@        DR.read() ===> " + retval);

            if (retval == ReturnCode_t.RETCODE_OK) {
                if (samples.value == null)
                    System.out.println(" @@@@@@@@@@@        samples.value = null");
                else {
                    System.out.println(" @@@@@@@@@@@        samples.value.length= " + samples.value.length);
                    for (int i = 0; i < samples.value.length; i++) {
                        System.out.println("    State       : "
                                + (si.value[i].instance_state == coredxConstants.DDS_ALIVE_INSTANCE_STATE
                                        ? "ALIVE"
                                        : "NOT ALIVE"));
                        System.out.println("    TimeStamp   : " + si.value[i].source_timestamp.sec + "."
                                + si.value[i].source_timestamp.nanosec);
                        System.out.println("    Handle      : " + si.value[i].instance_handle.value);
                        System.out.println("    WriterHandle: " + si.value[i].publication_handle.value);
                        System.out.println("    SampleRank  : " + si.value[i].sample_rank);
                        if (si.value[i].valid_data)
                            System.out.println("       XVel: " + samples.value[i].XVel_DDS);
                        System.out.println("       YVel: " + samples.value[i].YVel_DDS);
                        System.out.println(" CompassDir: " + samples.value[i].CompassDir_DDS);
                        System.out.println("     GPS_LT: " + samples.value[i].GPS_LT_DDS);
                        System.out.println("     GPS_LN: " + samples.value[i].GPS_LN_DDS);
                        System.out.println("     Log_DDS: " + samples.value[i].Log_DDS);

                        //Capture data values for display
                        BasicFragmentActivity.XVel = samples.value[i].XVel_DDS;
                        BasicFragmentActivity.YVel = samples.value[i].YVel_DDS;
                        BasicFragmentActivity.CompassDir = samples.value[i].CompassDir_DDS;
                        BasicFragmentActivity.GPS_LT = samples.value[i].GPS_LT_DDS;
                        BasicFragmentActivity.GPS_LN = samples.value[i].GPS_LN_DDS;
                        BasicFragmentActivity.Log_DDS = samples.value[i].Log_DDS;
                        BasicFragmentActivity.data_image_DDS = samples.value[i].data_image_DDS;
                    }
                }
                data_message.return_loan(samples, si);
            } else {
            }
            System.out.println(" @@@@@@@@@@@                             @@@@@@@@@@");
            System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
        };
    }
    ;

    System.out.println("STARTING -------------------------");
    DomainParticipantFactory dpf = DomainParticipantFactory.get_instance();
    dpf.set_license(license);
    dpf.get_default_participant_qos(dp_qos_tablet);
    DomainParticipant dp = null;

    System.out.println("CREATE PARTICIPANT ---------------");
    dp = dpf.create_participant(0, /* domain Id   */
            dp_qos_tablet,
            //null, /* default qos */
            null, /* no listener */
            0);

    if (dp == null) {
        //failed to create DomainParticipant -- bad license
        android.util.Log.e("CoreDX DDS", "Unable to create Tablet DomainParticipant.");
    }

    SubscriberQos sub_qos_tablet = new SubscriberQos();
    Log.i("Tablet", "creating publisher/subscriber");
    sub_tablet = dp.create_subscriber(sub_qos_tablet, null, 0);

    System.out.println("REGISTERING TYPE -----------------");
    dataDDSTypeSupport ts = new dataDDSTypeSupport();
    ReturnCode_t returnValue = ts.register_type(dp, null);

    if (returnValue != ReturnCode_t.RETCODE_OK) {
        System.out.println("ERROR registering type\n");
        return;
    }

    System.out.println("CREATE TOPIC ---------------------");

    /* create a DDS Topic with the FilterMsg data type. */
    Topic topics = dp.create_topic("dataDDS", ts.get_type_name(), DDS.TOPIC_QOS_DEFAULT, null, 0);

    if (topics == null) {
        System.out.println("Error creating topic");
        return;
    }

    System.out.println("CREATE SUBSCRIBER ----------------");
    SubscriberQos sub_qos = null;
    SubscriberListener sub_listener = null;
    Subscriber sub = dp.create_subscriber(sub_qos, sub_listener, 0);

    System.out.println("READER VARIABLES ----------------");
    DataReaderQos dr_qos = new DataReaderQos();
    sub.get_default_datareader_qos(dr_qos);
    dr_qos.entity_name.value = "JAVA_DR";
    dr_qos.history.depth = 10;
    DataReaderListener dr_listener = new TestDataReaderListener();

    System.out.println("CREATE DATAREADER ----------------");

    //Create DDS Data reader
    dataDDSDataReader dr = (dataDDSDataReader) sub.create_datareader(topics, DDS.DATAREADER_QOS_DEFAULT,
            dr_listener, DDS.DATA_AVAILABLE_STATUS);

    System.out.println("DATAREADER CREATED ----------------");

    //Cheack to see if DDS Data Reader worked 
    if (dr == null) {
        System.out.println("ERROR creating data reader\n");
        //return;
    }

    // We default to building our Fragment at runtime, but you can switch the layout here
    // to R.layout.activity_fragment_xml in order to have the Fragment added during the
    // Activity's layout inflation.

    setContentView(R.layout.holygrail);
    Log.i("Tablet", "called set content view");

    FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.center_pane_top); // You can find Fragments just like you would with a 
    // View by using FragmentManager.

    Log.i("Tablet", "...declare fragment");

    // If wLog.ie are using activity_fragment_xml.xml then this the fragment will not be
    // null, otherwise it will be.
    if (fragment == null) {

        //Image View Fragment
        Log.i("Debug", "...calling fragment center pane");
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.center_pane_top, new BasicFragment());
        ft.addToBackStack(null);

        //Logging Fragment
        Log.i("Debug", "...calling fragment left pane top");
        //ft.add(R.id.left_pane_top, new LoggingFragment());
        ft.add(R.id.left_pane_top, new LoggingFragment());
        ft.addToBackStack(null);

        //Connecting Fragment
        Log.i("Debug", "...calling fragment left pane bottom");
        //ft.add(R.id.left_pane_bottom,new ControllerFragment());
        ft.add(R.id.left_pane_bottom, new ConnectionFragment());
        ft.addToBackStack(null);

        //Compass Fragment
        Log.i("Debug", "...calling fragment right pane top");
        //ft.add(R.id.right_pane_top,new BasicFragment2());
        ft.add(R.id.right_pane_top, new BasicFragment2());
        ft.addToBackStack(null);

        //Navigation Fragment
        Log.i("Debug", "...calling fragment right pane bottom");
        //ft.add(R.id.center_pane_bottom,new NavigationFragment());
        ft.add(R.id.center_pane_bottom, new DualJoystickActivity());
        ft.addToBackStack(null);

        //Datalog Fragment
        Log.i("Debug", "...calling fragment middle pane bottom");
        //ft.add(R.id.right_pane_bottom,new DatalogFragment());
        ft.add(R.id.right_pane_bottom, new DatalogFragment());
        ft.addToBackStack(null);

        //Commit the fragment or it will not be added
        Log.i("Debug", "...comitting");
        ft.commit();
    }

    //Joystick variables
    txtX1 = (TextView) this.findViewById(R.id.TextViewX1);
    txtY1 = (TextView) this.findViewById(R.id.TextViewY1);
    txtX2 = (TextView) this.findViewById(R.id.TextViewX2);
    txtY2 = (TextView) this.findViewById(R.id.TextViewY2);
    joystick = (DualJoystickView) this.findViewById(R.id.dualjoystickView);

    JoystickMovedListener _listenerLeft = new JoystickMovedListener() {

        @Override
        public void OnMoved(int pan, int tilt) {
            txtX1.setText(Integer.toString(pan));
            txtY1.setText(Integer.toString(tilt));
        }

        @Override
        public void OnReleased() {
            txtX1.setText("released");
            txtY1.setText("released");
        }

        @Override
        public void OnReturnedToCenter() {
            txtX1.setText("stopped");
            txtY1.setText("stopped");
        };
    };

    JoystickMovedListener _listenerRight = new JoystickMovedListener() {

        @Override
        public void OnMoved(int pan, int tilt) {
            txtX2.setText(Integer.toString(pan));
            txtY2.setText(Integer.toString(tilt));
        }

        @Override
        public void OnReleased() {
            txtX2.setText("released");
            txtY2.setText("released");
        }

        @Override
        public void OnReturnedToCenter() {
            txtX2.setText("stopped");
            txtY2.setText("stopped");
        };
    };

    joystick.setOnJostickMovedListener(_listenerLeft, _listenerRight);

    //Compass Activities
    compassView = (CompassView) this.findViewById(R.id.compassView);
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    //  updateOrientation(new float[] {0, 0, 0});
    //  updateOrientation(calculateOrientation());

    // Hook up button presses to the appropriate event handler.
    // Quit Button -- not really necessary: The 'Back' button does 
    //   the same thing, but we create this just for fun..
    ((Button) findViewById(R.id.quitButton)).setOnClickListener(mQuitListener);

    tv_myAddr = (TextView) findViewById(R.id.myAddress);
    if (tv_myAddr != null)
        tv_myAddr.setText("<detecting>");
    mHandler.postDelayed(mUpdateMyAddress, 1000); // every 10 sec */

    //Updating Datalog fragment view
    tv_XVel = (TextView) findViewById(R.id.XVel);
    if (tv_XVel != null)
        tv_XVel.setText("<detecting>");

    tv_YVel = (TextView) findViewById(R.id.YVel);
    if (tv_YVel != null)
        tv_YVel.setText("<detecting>");

    tv_CompassDir = (TextView) findViewById(R.id.CompassDir);
    if (tv_CompassDir != null)
        tv_CompassDir.setText("<detecting>");

    tv_GPSLocation = (TextView) findViewById(R.id.GPSLocation);
    if (tv_GPSLocation != null)
        tv_GPSLocation.setText("<detecting>");

    tv_Log_DDS = (TextView) findViewById(R.id.loggingMessage);
    if (tv_Log_DDS != null)
        tv_Log_DDS.setText("<detecting>");

    mHandler.postDelayed(mUpdateDatalog, 500); // every 1 sec */
}