Bluetooth経由で通信する簡単なアプリケーションを作成しています。Bluetoothがオンになっている近くのデバイスを一覧表示する簡単なアクティビティをすでに作成しましたが、残念ながら、一部のデバイスがBluetoothネットワークから消えた(btがオフになった)ときにそのアイテムを削除できるように検出する方法がわかりません。リスト。
これは、近くのBTデバイスをListViewに追加するために作成したコードです。
mNewDevicesArrayAdapter = new BluetoothDeviceArrayAdapter(this, 0, new ArrayList<BluetoothDevice>());
lvDiscovered = (ListView)findViewById(R.id.bt_dev_discovered_list);
lvDiscovered.setAdapter(mNewDevicesArrayAdapter);
...
// The BroadcastReceiver that listens for discovered devices and
// changes the title when discovery is finished
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// If it's already paired, skip it, because it's been listed already
if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
mNewDevicesArrayAdapter.add(device);
}
// When discovery is finished, change the Activity title
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
// TODO show no devices found!
}
}
};
デバイスが消えた場合の該当するACTIONインテントは見つかりませんでした。おそらくACTION_DISCOVERY_FINISHEDを使用できますが、どのようにしたらよいでしょうか。
前もって感謝します!