@Override protected void onPause() { super.onPause(); scanLeDevice(false); mLeDeviceListAdapter.clear(); mLeDeviceListAdapter.notifyDataSetChanged(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bluetooth_scan); final BluetoothManager bluetooth_manager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); bluetooth_adapter = bluetooth_manager.getAdapter(); mHandler = new Handler(); if (bluetooth_adapter == null) { Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_LONG).show(); finish(); return; } if (!bluetooth_manager.getAdapter().isEnabled()) { Toast.makeText(this, "Bluetooth is turned off on this device currently", Toast.LENGTH_LONG) .show(); } else { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) { Toast.makeText( this, "The android version of this device is not compatible with Bluetooth Low Energy", Toast.LENGTH_LONG) .show(); } } // Will request that GPS be enabled for devices running Marshmallow or newer. LocationHelper.requestLocationForBluetooth(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) initializeScannerCallback(); mLeDeviceListAdapter = new LeDeviceListAdapter(); setListAdapter(mLeDeviceListAdapter); }