他のBluetoothデバイスを検出すると、検出された各デバイスに対して2つのブロードキャストが送信されます。最初のスキャンはスキャン中に送信され、スキャンが終了すると、見つかったすべてのデバイスのブロードキャストが一度に送信されます。私はSDKのBluetoothChatサンプルを適合させています。Android Bluetoothディスカバリー
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);
}
}
};
ありがとう:
は、ここに私の 'BroadcastReceiver' です!
私はあなたがSamsungデバイス、儀式であなたのアプリをテストしていると思いますか? – waqaslam
多分私はそれを逃したが、あなたの質問は何ですか? –
私はHTCでテストしています。問題は、どのデバイスにも2回見つけられないようにすることです。 –