0
Androidで検出可能なBLEデバイスのリストを保存するにはどうすればよいですか?発見可能なBluetooth LEデバイスのリストを保存しますか?
startDeviceScan(の私の実装に従ってください)方法:
private BluetoothAdapter.LeScanCallback mBleScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
Runnable r = new Runnable() {
@Override
public void run() {
Log.i(TAG, "Name: " + device.getName() + " (" + device.getAddress() + ")");
mNearestDevices[mCounter][0] = device.getName();
mNearestDevices[mCounter][1] = device.getAddress();
}
};
r.run();
}
};
もう一つの問題:
private String[][] mNearestDevices;
// ...
public String[][] startDeviceScan() {
Log.i(TAG, "Start device scan");
mNearestDevices = new String[n][2];
mCounter = 0;
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mScanning = false;
mBluetoothAdapter.stopLeScan(mBleScanCallback);
}
}, SCAN_PERIOD);
mScanning = true;
mBluetoothAdapter.startLeScan(mBleScanCallback);
return mNearestDevices;
}
これはデバイススキャンのコールバックです。 スキャンの完了をどのように待つことができますか?
あなたはmNearestDevicesからデバイスリストをすることができますし、それを保存します。 –