Android BLE device does not receive any beacon after it starts for a period of time, My app have initialized BLE at the beginning. even I restart my app, it still doesn't work,I have to restart Bluetooth. I don't know why it happened. This is my code below:
public void initBLE() {
// Use this check to determine whether BLE is supported on the device.
// Then you can
// selectively disable BLE-related features.
if (!mActivity.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_BLUETOOTH_LE)) {
if (CommonUtils.isDebug) {
Log.d(TAG,
mActivity.getResources().getString(
R.string.ble_not_supported));
}
return;
}
// Initializes a Bluetooth adapter. For API level 18 and above, get a
// reference to
// BluetoothAdapter through BluetoothManager.
final BluetoothManager bluetoothManager = (BluetoothManager) mActivity
.getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
// Checks if Bluetooth is supported on the device.
if (mBluetoothAdapter == null) {
if (CommonUtils.isDebug) {
Log.e(TAG,
mActivity.getResources().getString(
R.string.error_bluetooth_not_supported));
}
return;
}
mBluetoothAdapter.enable();
}
/** * Device scan callback. */
private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, int rssi,
byte[] scanRecord) {
final DevIBeacon ibeacon = BLEDevice.getDevicefromScanData(device,
rssi, scanRecord);
if (ibeacon == null) {
return;
}
synchronized (mBLEList) {
mBLEList.add(ibeacon);
}
}
};
private void scanLeDevice(final boolean enable) {
if (enable) {
isScanning = true;
mBluetoothAdapter.startLeScan(mLeScanCallback);
} else {
isScanning = false;
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
}
LeScanCallback does not receive any beacon..
Aucun commentaire:
Enregistrer un commentaire