2016-11-21 98 views
0

我是一個在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系統?有沒有更好的辦法?

+0

可以使用過時[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))並控制一切你自己。 –

+0

@MarkusKauppinen明白了。非常感謝你!我認爲如果有可能控制廣告間隔?我只找到三種模式[這裏](https://developer.android.com/reference/android/bluetooth/le/AdvertiseSettings.Builder.html#setAdvertiseMode(int))。或者它是一種廣告宣傳的方式,所以我可以控制廣告時間間隔。再次感謝你! – nikefd

+0

這些模式與掃描無關,但您可能是指'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設備都被檢測到。 –

回答

1

您可以自由控制掃描窗口的等價物,並通過啓動和停止掃描來更高級別地編碼。這正是開源Android Beacon Library確實與同等配置的參數:

beaconManager.setForegroundScanPeriod(...); 
beaconManager.setForegroundBetweenScanPeriod(...); 
+0

非常感謝。你的建議很棒!我還有關於廣告時間間隔的問題。我認爲如果有可能控制廣告間隔?我只是在[Android信標庫](http://altbeacon.github.io/android-beacon-library/javadoc/org/altbeacon/beacon/BeaconTransmitter.html)中找到'setAdvertiseMode',但找不到某種設置方法通告間隔如'setForegroundScanPeriod'。再次感謝你! – nikefd

+0

你想控制傳輸速率?例如。 1赫茲vs 10赫茲? – davidgyoung

+0

是的,可以做到嗎? @davidgyoung – nikefd