List of usage examples for android.bluetooth BluetoothAdapter getDefaultAdapter
public static synchronized BluetoothAdapter getDefaultAdapter()
From source file:com.kncwallet.wallet.ui.SendCoinsFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true);//from ww w . j a v a 2s . co m bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND); backgroundThread.start(); backgroundHandler = new Handler(backgroundThread.getLooper()); final String precision = prefs.getString(Constants.PREFS_KEY_BTC_PRECISION, Constants.PREFS_DEFAULT_BTC_PRECISION); btcPrecision = precision.charAt(0) - '0'; btcShift = precision.length() == 3 ? precision.charAt(2) - '0' : 0; }
From source file:com.t2.biofeedback.BioFeedbackService.java
/** * Sends a JSON encoded string containing the status of the bluetooth system and devices * name: name of paired bluetooth device * address: BT address of paired bluetooth device * enabled: whether or not the device is enabled by the user * // w w w . java 2 s .com * Note that a special name (system) is reserved for the bluetooth system in general * (to tell whether or not bluetooth is enabled by the user * * * @param context */ private void sendDeviceList() { boolean bluetoothEnabled = false; // First see if bluetooth is enabled BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { Log.e(TAG, "Device does not support Bluetooth"); return; } if (mBluetoothAdapter.isEnabled()) { bluetoothEnabled = true; } JSONArray jsonArray = new JSONArray(); try { JSONObject jsonObject = new JSONObject(); jsonObject.put("name", "system"); jsonObject.put("address", ""); jsonObject.put("enabled", bluetoothEnabled); jsonObject.put("connectionStatus", 0); // Don't care for this one jsonArray.put(jsonObject); } catch (JSONException e) { Log.e(TAG, e.toString()); } if (deviceManager != null) { BioFeedbackDevice[] bondedDevices = deviceManager.getBondedDevices(); BioFeedbackDevice[] enabledDevices = deviceManager.getEnabledDevices(); for (BioFeedbackDevice d : bondedDevices) { // See if it's enabled boolean enabled = false; int connectionStatus = CONN_IDLE; // Default for (BioFeedbackDevice dEnabled : enabledDevices) { if (d.getAddress().equalsIgnoreCase(dEnabled.getAddress())) { enabled = true; if (d.isConencted()) { connectionStatus = CONN_CONNECTED; } else if (d.isConnecting()) { connectionStatus = CONN_CONNECTING; } else { connectionStatus = CONN_PAIRED; } } } try { JSONObject jsonObject = new JSONObject(); jsonObject.put("name", d.getName()); jsonObject.put("address", d.getAddress()); jsonObject.put("enabled", enabled); jsonObject.put("connectionStatus", connectionStatus); jsonArray.put(jsonObject); } catch (JSONException e) { Log.e(TAG, e.toString()); } } Log.d(TAG, "JSON paired devices = " + jsonArray.toString()); // TOTO: we should probably change this from broadcast to use the ipc messaging channels Intent i = new Intent(); i.setAction("com.t2.biofeedback.service.status.BROADCAST"); i.putExtra(EXTRA_MESSAGE_TYPE, BroadcastMessage.Type.STATUS); i.putExtra(EXTRA_MESSAGE_ID, "STATUS_PAIRED_DEVICES"); i.putExtra(EXTRA_TIMESTAMP, System.currentTimeMillis()); i.putExtra(EXTRA_ADDRESS, jsonArray.toString()); sendBroadcast(i); } else { Log.e(TAG, "NEW no device manager"); } }
From source file:com.example.mego.adas.main.MainActivity.java
/** * Helper method to bluetooth connect with the device */// w ww. j av a 2 s . c o m private void connectBluetooth() { //show a progress dialog in the BluetoothServerActivity progressDialog = ProgressDialog.show(MainActivity.this, getString(R.string.bluetooth_connecting), getString(R.string.bluetooth_please_wait)); Completable.fromAction(() -> { if (btSocket == null || !isBtConnected) { //get the mobile bluetooth device myBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); //connects to the device's address and checks if it's available BluetoothDevice bluetoothDevice = myBluetoothAdapter.getRemoteDevice(address); //create a RFCOMM (SPP) connection btSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(myUUID); BluetoothAdapter.getDefaultAdapter().cancelDiscovery(); //start connection btSocket.connect(); } }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) .subscribe(new CompletableObserver() { @Override public void onSubscribe(Disposable d) { } @Override public void onComplete() { showToast(getString(R.string.bluetooth_connected)); connected = true; isBtConnected = true; progressDialog.dismiss(); mConnectedThread = new ConnectedThread(btSocket); mConnectedThread.start(); mConnectedThread.write("o"); } @Override public void onError(Throwable e) { progressDialog.dismiss(); showToast(getString(R.string.bluetooth_connection_failed)); finish(); } }); }
From source file:com.landenlabs.all_devtool.NetFragment.java
public void updateList() { // Time today = new Time(Time.getCurrentTimezone()); // today.setToNow(); // today.format(" %H:%M:%S") Date dt = new Date(); m_titleTime.setText(m_timeFormat.format(dt)); boolean expandAll = m_list.isEmpty(); m_list.clear();/* w w w. ja v a 2 s. c om*/ // Swap colors int color = m_rowColor1; m_rowColor1 = m_rowColor2; m_rowColor2 = color; ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); try { String androidIDStr = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID); addBuild("Android ID", androidIDStr); try { AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getContext()); final String adIdStr = adInfo.getId(); final boolean isLAT = adInfo.isLimitAdTrackingEnabled(); addBuild("Ad ID", adIdStr); } catch (IOException e) { // Unrecoverable error connecting to Google Play services (e.g., // the old version of the service doesn't support getting AdvertisingId). } catch (GooglePlayServicesNotAvailableException e) { // Google Play services is not available entirely. } /* try { InstanceID instanceID = InstanceID.getInstance(getContext()); if (instanceID != null) { // Requires a Google Developer project ID. String authorizedEntity = "<need to make this on google developer site>"; instanceID.getToken(authorizedEntity, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); addBuild("Instance ID", instanceID.getId()); } } catch (Exception ex) { } */ ConfigurationInfo info = actMgr.getDeviceConfigurationInfo(); addBuild("OpenGL", info.getGlEsVersion()); } catch (Exception ex) { m_log.e(ex.getMessage()); } // --------------- Connection Services ------------- try { ConnectivityManager connMgr = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = connMgr.getActiveNetworkInfo(); if (netInfo != null) { Map<String, String> netListStr = new LinkedHashMap<String, String>(); putIf(netListStr, "Available", "Yes", netInfo.isAvailable()); putIf(netListStr, "Connected", "Yes", netInfo.isConnected()); putIf(netListStr, "Connecting", "Yes", !netInfo.isConnected() && netInfo.isConnectedOrConnecting()); putIf(netListStr, "Roaming", "Yes", netInfo.isRoaming()); putIf(netListStr, "Extra", netInfo.getExtraInfo(), !TextUtils.isEmpty(netInfo.getExtraInfo())); putIf(netListStr, "WhyFailed", netInfo.getReason(), !TextUtils.isEmpty(netInfo.getReason())); if (Build.VERSION.SDK_INT >= 16) { putIf(netListStr, "Metered", "Avoid heavy use", connMgr.isActiveNetworkMetered()); } netListStr.put("NetworkType", netInfo.getTypeName()); if (connMgr.getAllNetworkInfo().length > 1) { netListStr.put("Available Networks:", " "); for (NetworkInfo netI : connMgr.getAllNetworkInfo()) { if (netI.isAvailable()) { netListStr.put(" " + netI.getTypeName(), netI.isAvailable() ? "Yes" : "No"); } } } if (netInfo.isConnected()) { try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr .hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { if (inetAddress.getHostAddress() != null) { String ipType = (inetAddress instanceof Inet4Address) ? "IPv4" : "IPv6"; netListStr.put(intf.getName() + " " + ipType, inetAddress.getHostAddress()); } // if (!TextUtils.isEmpty(inetAddress.getHostName())) // listStr.put( "HostName", inetAddress.getHostName()); } } } } catch (Exception ex) { m_log.e("Network %s", ex.getMessage()); } } addBuild("Network...", netListStr); } } catch (Exception ex) { m_log.e("Network %s", ex.getMessage()); } // --------------- Telephony Services ------------- TelephonyManager telephonyManager = (TelephonyManager) getActivity() .getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null) { Map<String, String> cellListStr = new LinkedHashMap<String, String>(); try { cellListStr.put("Version", telephonyManager.getDeviceSoftwareVersion()); cellListStr.put("Number", telephonyManager.getLine1Number()); cellListStr.put("Service", telephonyManager.getNetworkOperatorName()); cellListStr.put("Roaming", telephonyManager.isNetworkRoaming() ? "Yes" : "No"); cellListStr.put("Type", getNetworkTypeName(telephonyManager.getNetworkType())); if (Build.VERSION.SDK_INT >= 17) { if (telephonyManager.getAllCellInfo() != null) { for (CellInfo cellInfo : telephonyManager.getAllCellInfo()) { String cellName = cellInfo.getClass().getSimpleName(); int level = 0; if (cellInfo instanceof CellInfoCdma) { level = ((CellInfoCdma) cellInfo).getCellSignalStrength().getLevel(); } else if (cellInfo instanceof CellInfoGsm) { level = ((CellInfoGsm) cellInfo).getCellSignalStrength().getLevel(); } else if (cellInfo instanceof CellInfoLte) { level = ((CellInfoLte) cellInfo).getCellSignalStrength().getLevel(); } else if (cellInfo instanceof CellInfoWcdma) { if (Build.VERSION.SDK_INT >= 18) { level = ((CellInfoWcdma) cellInfo).getCellSignalStrength().getLevel(); } } cellListStr.put(cellName, "Level% " + String.valueOf(100 * level / 4)); } } } for (NeighboringCellInfo cellInfo : telephonyManager.getNeighboringCellInfo()) { int level = cellInfo.getRssi(); cellListStr.put("Cell level%", String.valueOf(100 * level / 31)); } } catch (Exception ex) { m_log.e("Cell %s", ex.getMessage()); } if (!cellListStr.isEmpty()) { addBuild("Cell...", cellListStr); } } // --------------- Bluetooth Services (API18) ------------- if (Build.VERSION.SDK_INT >= 18) { try { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter != null) { Map<String, String> btListStr = new LinkedHashMap<String, String>(); btListStr.put("Enabled", bluetoothAdapter.isEnabled() ? "yes" : "no"); btListStr.put("Name", bluetoothAdapter.getName()); btListStr.put("ScanMode", String.valueOf(bluetoothAdapter.getScanMode())); btListStr.put("State", String.valueOf(bluetoothAdapter.getState())); Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices(); // If there are paired devices if (pairedDevices.size() > 0) { // Loop through paired devices for (BluetoothDevice device : pairedDevices) { // Add the name and address to an array adapter to show in a ListView btListStr.put("Paired:" + device.getName(), device.getAddress()); } } BluetoothManager btMgr = (BluetoothManager) getActivity() .getSystemService(Context.BLUETOOTH_SERVICE); if (btMgr != null) { // btMgr.getAdapter(). } addBuild("Bluetooth", btListStr); } } catch (Exception ex) { } } // --------------- Wifi Services ------------- final WifiManager wifiMgr = (WifiManager) getContext().getApplicationContext() .getSystemService(Context.WIFI_SERVICE); if (wifiMgr != null && wifiMgr.isWifiEnabled() && wifiMgr.getDhcpInfo() != null) { if (mSystemBroadcastReceiver == null) { mSystemBroadcastReceiver = new SystemBroadcastReceiver(wifiMgr); getActivity().registerReceiver(mSystemBroadcastReceiver, INTENT_FILTER_SCAN_AVAILABLE); } if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { if (wifiMgr.getScanResults() == null || wifiMgr.getScanResults().size() != mLastScanSize) { mLastScanSize = wifiMgr.getScanResults().size(); wifiMgr.startScan(); } } Map<String, String> wifiListStr = new LinkedHashMap<String, String>(); try { DhcpInfo dhcpInfo = wifiMgr.getDhcpInfo(); wifiListStr.put("DNS1", Formatter.formatIpAddress(dhcpInfo.dns1)); wifiListStr.put("DNS2", Formatter.formatIpAddress(dhcpInfo.dns2)); wifiListStr.put("Default Gateway", Formatter.formatIpAddress(dhcpInfo.gateway)); wifiListStr.put("IP Address", Formatter.formatIpAddress(dhcpInfo.ipAddress)); wifiListStr.put("Subnet Mask", Formatter.formatIpAddress(dhcpInfo.netmask)); wifiListStr.put("Server IP", Formatter.formatIpAddress(dhcpInfo.serverAddress)); wifiListStr.put("Lease Time(sec)", String.valueOf(dhcpInfo.leaseDuration)); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); if (wifiInfo != null) { wifiListStr.put("LinkSpeed Mbps", String.valueOf(wifiInfo.getLinkSpeed())); int numberOfLevels = 10; int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels + 1); wifiListStr.put("Signal%", String.valueOf(100 * level / numberOfLevels)); if (Build.VERSION.SDK_INT >= 23) { wifiListStr.put("MAC", getMacAddr()); } else { wifiListStr.put("MAC", wifiInfo.getMacAddress()); } } } catch (Exception ex) { m_log.e("Wifi %s", ex.getMessage()); } if (!wifiListStr.isEmpty()) { addBuild("WiFi...", wifiListStr); } try { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { List<ScanResult> listWifi = wifiMgr.getScanResults(); if (listWifi != null && !listWifi.isEmpty()) { int idx = 0; for (ScanResult scanResult : listWifi) { Map<String, String> wifiScanListStr = new LinkedHashMap<String, String>(); wifiScanListStr.put("SSID", scanResult.SSID); if (Build.VERSION.SDK_INT >= 23) { wifiScanListStr.put(" Name", scanResult.operatorFriendlyName.toString()); wifiScanListStr.put(" Venue", scanResult.venueName.toString()); } // wifiScanListStr.put(" BSSID ",scanResult.BSSID); wifiScanListStr.put(" Capabilities", scanResult.capabilities); // wifiScanListStr.put(" Center Freq", String.valueOf(scanResult.centerFreq0)); // wifiScanListStr.put(" Freq width", String.valueOf(scanResult.channelWidth)); wifiScanListStr.put(" Level, Freq", String.format("%d, %d", scanResult.level, scanResult.frequency)); if (Build.VERSION.SDK_INT >= 17) { Date wifiTime = new Date(scanResult.timestamp); wifiScanListStr.put(" Time", wifiTime.toLocaleString()); } addBuild(String.format("WiFiScan #%d", ++idx), wifiScanListStr); } } } } catch (Exception ex) { m_log.e("WifiList %s", ex.getMessage()); } try { List<WifiConfiguration> listWifiCfg = wifiMgr.getConfiguredNetworks(); for (WifiConfiguration wifiCfg : listWifiCfg) { Map<String, String> wifiCfgListStr = new LinkedHashMap<String, String>(); if (Build.VERSION.SDK_INT >= 23) { wifiCfgListStr.put("Name", wifiCfg.providerFriendlyName); } wifiCfgListStr.put("SSID", wifiCfg.SSID); String netStatus = ""; switch (wifiCfg.status) { case WifiConfiguration.Status.CURRENT: netStatus = "Connected"; break; case WifiConfiguration.Status.DISABLED: netStatus = "Disabled"; break; case WifiConfiguration.Status.ENABLED: netStatus = "Enabled"; break; } wifiCfgListStr.put(" Status", netStatus); wifiCfgListStr.put(" Priority", String.valueOf(wifiCfg.priority)); if (null != wifiCfg.wepKeys) { // wifiCfgListStr.put(" wepKeys", TextUtils.join(",", wifiCfg.wepKeys)); } String protocols = ""; if (wifiCfg.allowedProtocols.get(WifiConfiguration.Protocol.RSN)) protocols = "RSN "; if (wifiCfg.allowedProtocols.get(WifiConfiguration.Protocol.WPA)) protocols = protocols + "WPA "; wifiCfgListStr.put(" Protocols", protocols); String keyProt = ""; if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE)) keyProt = "none"; if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_EAP)) keyProt = "WPA+EAP "; if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_PSK)) keyProt = "WPA+PSK "; wifiCfgListStr.put(" Keys", keyProt); if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE)) { // Remove network connections with no Password. // wifiMgr.removeNetwork(wifiCfg.networkId); } addBuild("WiFiCfg #" + wifiCfg.networkId, wifiCfgListStr); } } catch (Exception ex) { m_log.e("Wifi Cfg List %s", ex.getMessage()); } } if (expandAll) { // updateList(); int count = m_list.size(); for (int position = 0; position < count; position++) m_listView.expandGroup(position); } m_adapter.notifyDataSetChanged(); }
From source file:com.nordicsemi.nrfUARTv2.MainActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_SELECT_DEVICE: //When the DeviceListActivity return, with the selected device address if (resultCode == Activity.RESULT_OK && data != null) { String deviceAddress = data.getStringExtra(BluetoothDevice.EXTRA_DEVICE); mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress); Log.d(TAG, "... onActivityResultdevice.address==" + mDevice + "mserviceValue" + mService); ((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName() + " - connecting"); mService.connect(deviceAddress); }// w w w . j a v a 2 s. c om break; case REQUEST_SELECT_DEVICE2: //When the DeviceListActivity return, with the selected device address if (resultCode == Activity.RESULT_OK && data != null) { String deviceAddress = data.getStringExtra(BluetoothDevice.EXTRA_DEVICE); mDevice2 = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress); Log.d(TAG, "... onActivityResultdevice.address==" + mDevice2 + "mserviceValue" + mService2); ((TextView) findViewById(R.id.deviceName)).setText(mDevice2.getName() + " - connecting"); mService2.connect(deviceAddress); mCollecting = true; } break; case REQUEST_ENABLE_BT: // When the request to enable Bluetooth returns if (resultCode == Activity.RESULT_OK) { Toast.makeText(this, "Bluetooth has turned on ", Toast.LENGTH_SHORT).show(); } else { // User did not enable Bluetooth or an error occurred Log.d(TAG, "BT not enabled"); Toast.makeText(this, "Problem in BT Turning ON ", Toast.LENGTH_SHORT).show(); finish(); } break; default: Log.e(TAG, "wrong request code"); break; } }
From source file:it.angrydroids.epub3reader.MainActivity.java
private void ConnectBLEDevice() { for (BluetoothDevice listDev : deviceList) { if (listDev.getName().equals(UartService.BLEDeviceName)) { mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(listDev.getAddress()); mService.connect(listDev.getAddress()); break; }/*from w w w. ja v a 2 s . c om*/ } }
From source file:com.example.bluetooth_faster_connection.MainActivity.java
public static String getBluetoothMacAddress() { BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // if device does not support Bluetooth if (mBluetoothAdapter == null) { Log.d(TAG, "device does not support bluetooth"); return null; }//from ww w. j a v a 2 s .c o m return mBluetoothAdapter.getAddress(); }
From source file:com.evothings.BLE.java
private void reset(final CordovaArgs args, final CallbackContext cc) throws JSONException { mResetCallbackContext = null;//ww w . j a va 2 s . c o m BluetoothAdapter a = BluetoothAdapter.getDefaultAdapter(); if (mScanCallbackContext != null) { a.stopLeScan(this); mScanCallbackContext = null; } int state = a.getState(); //STATE_OFF, STATE_TURNING_ON, STATE_ON, STATE_TURNING_OFF. if (state == BluetoothAdapter.STATE_TURNING_ON) { // reset in progress; wait for STATE_ON. mResetCallbackContext = cc; return; } if (state == BluetoothAdapter.STATE_TURNING_OFF) { // reset in progress; wait for STATE_OFF. mResetCallbackContext = cc; return; } if (state == BluetoothAdapter.STATE_OFF) { boolean res = a.enable(); if (res) { mResetCallbackContext = cc; } else { cc.error("enable"); } return; } if (state == BluetoothAdapter.STATE_ON) { boolean res = a.disable(); if (res) { mResetCallbackContext = cc; } else { cc.error("disable"); } return; } cc.error("Unknown state: " + state); }
From source file:com.jins_meme.bridge.MainActivity.java
private void checkBluetoothEnable() { if (!isMemeConnected()) { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter != null && !bluetoothAdapter.isEnabled()) { Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(intent, 0); } else if (bluetoothAdapter != null && bluetoothAdapter.isEnabled()) { Log.d("DEBUG", "MAIN:: Initialize MEME LIB"); initMemeLib();/* w w w. j a v a 2 s . c o m*/ scanAndConnectToLastConnectedMeme(); } } }
From source file:com.mooshim.mooshimeter.main.ScanActivity.java
public synchronized void startScan() { if (mScanOngoing) return;/* w w w. j a v a 2 s . c o m*/ mScanOngoing = true; final Handler h = new Handler(); mBtnScan.setEnabled(false); updateScanningButton(false); // Prune disconnected meters List<MooshimeterDevice> remove = new ArrayList<MooshimeterDevice>(); for (MooshimeterDevice m : mMeterList) { if (m.mConnectionState == BluetoothProfile.STATE_DISCONNECTED) { remove.add(m); } } for (MooshimeterDevice m : remove) { mDeviceScrollView.removeView(mTileList.remove(mMeterList.indexOf(m))); mMeterList.remove(m); mMeterDict.remove(m.getAddress()); } refreshAllMeterTiles(); final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (!bluetoothAdapter.startLeScan(mLeScanCallback)) { // Starting the scan failed! Log.e(TAG, "Failed to start BLE Scan"); setError("Failed to start scan"); } h.postDelayed(new Runnable() { @Override public void run() { mBtnScan.setEnabled(true); updateScanningButton(false); final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter.stopLeScan(mLeScanCallback); mScanOngoing = false; } }, 5000); }