Android:BLUETOOTH:
我正在尝试将设备标记为"在范围"使用以下方法:
在BroadCast接收器内部写入以下条件:
如果BluetoothDevice.ACTION_FOUND
为真且设备为BluetoothDevice.BOND_BONDED
,那么
电话是"在Range"
问题:
假设设备被调用' ABC'显示为"在范围" ;现在,如果我关闭此客户端设备的蓝牙' ABC' ,代码仍显示为" In Range" ?
代码段:
protected void onStart() {<br>
super.onStart();<br>
newListView.setOnItemClickListener(listItemClicked);<br>
final BroadcastReceiver mReceiver = new BroadcastReceiver() {<br>
@Override<br>
public void onReceive(Context context, Intent intent) {<br>
if (BluetoothDevice.ACTION_FOUND.equals(action)) {<br>
BluetoothDevice device = intent<br>
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);<br>
if ((device.getBondState() != BluetoothDevice.BOND_BONDED)) {<br>
// Do Something<br>
} else {<br>
for(BluetoothDevice newDevice : arrayOnlineBluetoothDevices)<br>
{<br>
if (newDevice.getAddress().equals(device.getAddress()))<br>
{<br>
flag=true;<br>
continue;<br>
}<br>
}<br>
mPairedDevicesArrayAdapter.add(device.getName());<br>
rangeListView.setAdapter(mPairedDevicesArrayAdapter); // This is where I Tag any Device as <br>
}<br>
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);<br>
registerReceiver(mReceiver, filter);<br>
}}}}<br>
感谢。
答案 0 :(得分:0)
您可以在BroadcastReceiver中查找ACTION_ACL_DISCONNECT操作。关闭设备的蓝牙后,可能需要一些时间。通常约10秒。