resultCode, Intent data) { if (requestCode == REQUEST_ENABLE_BT) { if (resultCode == Activity.RESULT_OK) { // Bluetooth has turned on } else { // User did not enable Bluetooth or an error occurred } } } Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); ေյῘῴ
manager.getAdapter(); adapter.startLeScan(scanCallback); adapter.stopLeScan(scanCallback); ଦ֞#MVFUPPUI"EBQUFS Ῐෆ⇨ ඏෆ⇨ This method was deprecated in API level 21 API level 18
void onLeScan(final BluetoothDevice device , final int rssi , byte[] scanRecord) { addDevice(device, rssi); // Add device to list } }; ෆ⇨֥$BMMCBDL This method was deprecated in API level 21 API level 18
void onConnectionStateChange(BluetoothGatt gatt , int status, int newState) { switch (newState) { case BluetoothProfile.STATE_CONNECTED: // do discoverServices break; case BluetoothProfile.STATE_DISCONNECTED: break; case BluetoothProfile.STATE_CONNECTING: case BluetoothProfile.STATE_DISCONNECTING: break; } } // More ... }; Connect ’ࢤ⊬ᇂ (BUU$BMMCBDL API level 18
mGattCallback = new BluetoothGattCallback() { // ... Continued @Override public void onServicesDiscovered(BluetoothGatt gatt , int status) { if (status == BluetoothGatt.GATT_SUCCESS) { // Do Something } } // More ... }; (BUU$BMMCBDL ⇟
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { // ... Continued @Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { // Do Something } } // More ... }; (BUU$BMMCBDL ⇟