예제 #1
0
 @Override
 public void onResume() {
   super.onResume();
   if (mNearbyCapable && PrefUtils.hasEnabledBle(this)) {
     mDeviceManager.startSearchingForDevices();
   }
 }
예제 #2
0
 // Handles a click on the Nearby menu item. Recognizes several states:
 // 1. If the NearbyFragment is currently visible, does nothing.
 // 2. If the user has not enabled Nearby, presents them with a legalese screen asking them to
 // opt in.
 // 3. If the device's Bluetooth is disabled, ask the user to enable it.
 // 4. Otherwise, shows the fragment.
 private void handleNearbyClick() {
   final FragmentManager manager = getFragmentManager();
   Fragment fragment = manager.findFragmentByTag(NEARBY_FRAGMENT_TAG);
   if (fragment != null && fragment.isVisible()) {
     return;
   }
   if (!PrefUtils.hasEnabledBle(this)) {
     // If the user has not enabled Nearby, present them with a legalese screen asking them
     // to do so.
     Intent intent = new Intent(this, NearbyEulaActivity.class);
     startActivityForResult(intent, REQUEST_ENABLE_NEARBY);
     return;
   }
   if (!mDeviceManager.isEnabled()) {
     // If the user's bluetooth is not enabled, ask them politely to turn it on. Beginning
     // to search for devices should happen in onStart?
     DialogFragment dialogFragment = new EnableBluetoothDialogFragment();
     dialogFragment.show(getFragmentManager(), "EnableBluetoothDialogFragment");
     return;
   }
   // Otherwise, the user has opted into BLE and their Bluetooth device is turned on!
   showNearbyFragment(NEARBY_FRAGMENT_TAG);
 }