コード例 #1
0
 // Updates the nearby button's text to be the number of devices found. If no devices have been
 // found, the text is set to "Nearby".
 private void updateNearbyButton() {
   int count = mDeviceManager.getAdapter().getCount();
   final String text =
       (count == 0 ? "" : (String.valueOf(count) + " "))
           + getResources().getString(R.string.map_nearby_button);
   if (mNearbyButton != null) {
     mNearbyButton.setText(text);
     mNearbyButton.setSelected(count > 0);
   }
 }
コード例 #2
0
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
 private boolean initNearby() {
   PackageManager pm = getPackageManager();
   if (pm != null && pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
     BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
     BluetoothAdapter adapter = manager.getAdapter();
     if (adapter != null) {
       MetadataResolver.initialize(this);
       mDeviceManager = new NearbyDeviceManager(this, adapter);
       mDeviceManager
           .getAdapter()
           .registerDataSetObserver(
               new DataSetObserver() {
                 @Override
                 public void onChanged() {
                   updateNearbyButton();
                 }
               });
       return true;
     }
   }
   return false;
 }