当发现其他蓝牙设备时,我为每个找到的设备发送了2个广播。第一个是在扫描期间发送的,当完成扫描时,一次发送所有找到的设备的广播。我正在调整SDK中的BluetoothChat示例。Android蓝牙发现
这里是我的 '广播接收器':
private final BroadcastReceiver foundRec = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(BluetoothDevice.ACTION_FOUND)) {
Log.e(TAG, "--- device found ---");
BluetoothDevice dev = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (dev.getBondState() == BluetoothDevice.BOND_BONDED) {
availableDevices.add(dev.getName() + " (paired)");
} else {
availableDevices.add(dev.getName());
}
} else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED)){
Log.d(TAG, "DISCOVERY STARTED");
findViewById(R.id.lookup).setVisibility(View.VISIBLE);
}
}
};
谢谢!
我相信你正在测试你的应用程序在三星设备,仪式? – waqaslam 2012-03-23 22:11:09
也许我错过了,但你的问题是什么? – 2012-03-23 22:31:32
我正在测试HTC。问题是如何避免每次发现两次设备。 – 2012-03-24 06:31:18