最近Androidを学んでいます。私は、Bluetoothデバイスを検索する機能を実装しようとしました。これまでにペア設定したすべてのデバイスを一覧表示することはできますが、新しいデバイスを検出することはできません。Bluetoothスキャンで何も返されない
権限はAndroidManifest.xmlに設定されています。
public void listDiscoverableDevices(boolean status) {
// Create a BroadcastReceiver for ACTION_FOUND
mBluetoothAdapter.cancelDiscovery();
mArrayAdapter.clear();
mDisplay.setText("Search");
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
//BluetoothDevice.
if(BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
mArrayAdapter.add(device.getAddress());
} else if(BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
//mDisplay.setText(action);
mArrayAdapter.add(action);
} else if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
//mDisplay.setText(action);
mArrayAdapter.add(action);
}
}
};
// Register the BroadcastReceiver
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(mReceiver, filter); // Don't forget to unregister during onDestroy
if(!mBluetoothAdapter.startDiscovery()) {
mDisplay.setText("Discover failed!");
}
}
BluetoothDevice.ACTION_FOUNDアクションが受信されることはありませんように私には思える:
は、ここに私のコードです。私は2日間これと闘ってきました。何か案が?
ありがとう、
おい、あなたは私の日を救った! – psv
私はそれが助けてうれしいです:) – Booo