我是一個在android的新人。我想在我的android設備中設置BLE掃描間隔和窗口,以便做一個關於鄰居發現的實驗。我在谷歌搜索的答案,知道有在android's source code約BLE掃描間隔和窗戶有些定義如下如何設置BLE掃描間隔和Windows沒有在Android中選擇模式?
/**
* Scan params corresponding to regular scan setting
*/
private static final int SCAN_MODE_LOW_POWER_WINDOW_MS = 500;
private static final int SCAN_MODE_LOW_POWER_INTERVAL_MS = 5000;
private static final int SCAN_MODE_BALANCED_WINDOW_MS = 2000;
private static final int SCAN_MODE_BALANCED_INTERVAL_MS = 5000;
private static final int SCAN_MODE_LOW_LATENCY_WINDOW_MS = 5000;
private static final int SCAN_MODE_LOW_LATENCY_INTERVAL_MS = 5000;
/**
* Scan params corresponding to batch scan setting
*/
private static final int SCAN_MODE_BATCH_LOW_POWER_WINDOW_MS = 1500;
private static final int SCAN_MODE_BATCH_LOW_POWER_INTERVAL_MS = 150000;
private static final int SCAN_MODE_BATCH_BALANCED_WINDOW_MS = 1500;
private static final int SCAN_MODE_BATCH_BALANCED_INTERVAL_MS = 15000;
private static final int SCAN_MODE_BATCH_LOW_LATENCY_WINDOW_MS = 1500;
private static final int SCAN_MODE_BATCH_LOW_LATENCY_INTERVAL_MS = 5000;
如果我想改變的值,這是否意味着我應該編譯Android系統?有沒有更好的辦法?
可以使用過時[startLeScan](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html# startLeScan(android.bluetooth.BluetoothAdapter.LeScanCallback))和[stopLeScan](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#stopLeScan(android.bluetooth.BluetoothAdapter.LeScanCallback))並控制一切你自己。 –
@MarkusKauppinen明白了。非常感謝你!我認爲如果有可能控制廣告間隔?我只找到三種模式[這裏](https://developer.android.com/reference/android/bluetooth/le/AdvertiseSettings.Builder.html#setAdvertiseMode(int))。或者它是一種廣告宣傳的方式,所以我可以控制廣告時間間隔。再次感謝你! – nikefd
這些模式與掃描無關,但您可能是指'ScanSettings'。它們也僅與新的掃描方式有關,與舊掃描方式有關,您可以決定掃描的頻率和掃描的時間。只需用'startLeScan'開始並用'stopLeScan'停下來即可。在[https://kittensandcode.blogspot.fi/2014/08/ibeacons-and-android-parsing-uuid-major.html](https://kittensandcode。)上有一個很好的例子。 blogspot.fi/2014/08/ibeacons-and-android-parsing-uuid-major.html)。該代碼處理iBeacons,但是當然還有任何BLE設備都被檢測到。 –