Android搭載端末の名前が「ABC」で始まるペアのBluetooth低エネルギーデバイスをプログラム的に削除します。AndroidでペアリングされたすべてのBluetoothデバイスを削除します
私はAndroidスタジオを使用しています。あなたがした方法を書くことができ、すべての結合したデバイスを取得するために、BLE(低エネルギーブルートゥース)、 に関する特定されている場合は、すべてのデバイスを登録解除するには
Android搭載端末の名前が「ABC」で始まるペアのBluetooth低エネルギーデバイスをプログラム的に削除します。AndroidでペアリングされたすべてのBluetoothデバイスを削除します
私はAndroidスタジオを使用しています。あなたがした方法を書くことができ、すべての結合したデバイスを取得するために、BLE(低エネルギーブルートゥース)、 に関する特定されている場合は、すべてのデバイスを登録解除するには
は、このコード
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
try {
if(device.getName().contains("abc")){
Method m = device.getClass()
.getMethod("removeBond", (Class[]) null);
m.invoke(device, (Object[]) null);
}
} catch (Exception e) {
Log.e("fail", e.getMessage());
}
}
}
を使用しています。
public List<BluetoothDevice> getConnectedDevices() {
BluetoothManager btManager = (BluetoothManager)getSystemService(BLUETOOTH_SERVICE);
return btManager.getConnectedDevices(BluetoothProfile.GATT);
}
これは、GATTプロファイルで接続されたBLEデバイスのリストを返します。あなたは、単にdisconnectメソッドを呼び出すことができます切断するには
List<BluetoothDevice> btdevices = getConnectedDevices();
for(int i=0;i<btdevices.size();i++)
{
//match your device here
Log.d("saurav"," BLE Name:"+btdevices.get(i).getName());
}
: この場合、名前はあなたがようdisconnetしたいデバイスを確認して取得します。 gattインスタンス(BLEデバイスの接続に使用したのと同じgattインスタンス)で切断する必要があります。
public void disconnect() {
if (gatt == null) {
return;
}
gatt.disconnect();
}
これにより、BLEデバイスの接続が切断されます。私は個人的にteste tshiを持っていて、私のために働いています。