我是一个在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设备都被检测到。 –