0
的Android:藍牙:Android的藍牙:顯示範圍內的設備附近
我試圖國旗的設備爲「位於範圍內」用下面的方法:
裏面的廣播接收機以下條件寫的是:
如果BluetoothDevice.ACTION_FOUND
是真實的,該設備是BluetoothDevice.BOND_BONDED
,然後 手機 「位於範圍內」
問題:
假設被叫做「ABC」的設備顯示爲「In Range」;現在如果我關閉此客戶端設備'ABC'的藍牙,代碼仍顯示爲「範圍內」?
代碼段:
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>
感謝。