У меня проблемы с использованием startDiscovery (). Вот проблема, я зарегистрировал следующее содержимое для моего BroadcastReceiver следующим образом:
IntentFilter filterFound = new IntentFilter(BluetoothDevice.ACTION_FOUND);
IntentFilter filterStart = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
IntentFilter filterStop = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(myReceiver, filterFound);
registerReceiver(myReceiver, filterStart);
registerReceiver(myReceiver, filterStop);
Вот мой приемник:
private BroadcastReceiver myReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "onReceive (myReceiver)");
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);
// Add the name and address to an array adapter to show in a ListView
Log.d(TAG,device.getName() + " " + device.getAddress());
deviceListAdapter.add(device.getName() + "\n" + device.getAddress());
}
if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
Log.d(TAG, "Started discovery");
}
if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
Log.d(TAG, "Finished discovery");
}
}
};
Когда я вызываю startDiscovery на моем адаптере Bluetooth (Bluetooth уже существует и включен), ничего не происходит, и я не вижу ничего в logcat относительно BroadcastReceiver.
Вы уже сталкивались с такой проблемой? Любая помощь приветствуется:)
Спасибо