Я хочу фильтровать BluetoothDevice при обнаружении и сохранять только те, которые запускаются при прослушивании одним и тем же программным обеспечением. Например, образец Android BluetoothChat, он должен показывать только те устройства bluetooth, которые запускаются BluetoothChat тоже.Как отфильтровать BluetoothDevice при обнаружении
Вот мой код.
public class DeviceListActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Setup UI here
......
// Register for broadcasts when a device is discovered
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
this.registerReceiver(mReceiver, filter);
// Register for broadcasts when discovery has finished
filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
this.registerReceiver(mReceiver, filter);
// Get the local Bluetooth adapter
mBtAdapter = BluetoothAdapter.getDefaultAdapter();
// Request discover from BluetoothAdapter
mBtAdapter.startDiscovery();
}
// 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();
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// *** My problem is here. I got a BluetoothDevice now, but how can I
// *** check whether it is created by my software?
// *** if I can't, I have to add all of them to my list, and when user
// *** chooses it, connection will fail if it's not created by my software.
mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}
// When discovery is finished, change the Activity title
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
// Discovery is finished...
// wrap up code here...
......
}
}
};
}