几分钟后设备锁定时,蓝牙不会检测到IBKS USB信标

时间:2017-09-11 10:52:51

标签: android bluetooth

我使用Alt-beacon作为库来管理我的IBKS USB信标。当我启动蓝牙服务并激活扫描过程时,会检测到信标并且我的应用程序正常工作。但是,几分钟后设备锁定,蓝牙无法检测到任何信标。

我的BeaconRanging.class的定义:

public class BeaconRaging extends Service implements BeaconConsumer {

  private final String TAG = "ALTBEACON";

  private BeaconManager beaconManager;
  private List<String> beaconList;

  private List<String> scannedDevicesList;
  private ArrayAdapter<String> adapter;

  ListView devicesList;
  ......

方法onCreate():

@Override
public void onCreate()
{
    Log.d(TAG, "onCreate de BeaconRanging");
    this.beaconManager = BeaconManager.getInstanceForApplication(this);
    this.beaconManager.bind(this);
    this.beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
    this.beaconManager.setAndroidLScanningDisabled(true);
    this.beaconManager.setBackgroundMode(true);
    this.beaconManager.setBackgroundScanPeriod(2100l);
    this.beaconManager.setBackgroundBetweenScanPeriod(2900l);
    this.beaconManager.setForegroundScanPeriod(21001);
    this.beaconManager.setForegroundBetweenScanPeriod(29001);
    this.beaconList = new ArrayList<>();

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "worker");
}

方法onDestroy():

@Override
public void onDestroy()
{
    super.onDestroy();
    beaconManager.unbind(this);
}

方法onStartCommand():

@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
    return START_STICKY;
}

方法onBeaconServiceConnect():

@Override
public void onBeaconServiceConnect() {
    beaconManager.addRangeNotifier(new RangeNotifier() {
        @Override
        public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
            Log.i("JSON", "Busqueda BLE");
            Log.i("JSON", String.valueOf(beacons.size()));
            beaconList = new ArrayList<>();
            for(Beacon beacon: beacons){
                Log.d(TAG, "[BEACON] " + beacon.getIdentifiers().toString() + "; "+ beacon.getDistance());
                beaconList.add(new RawBeacon(beacon.getId1().toString(), beacon.getId2().toInt(), beacon.getId3().toInt(), beacon.getDistance()));
            }
            publishResults();
        }
    });

    try {
        beaconManager.startRangingBeaconsInRegion(new Region(pam.getUuid(), null, null, null));
    } catch (RemoteException e) {    }
}

此问题出现取决于移动设备和Android版本。就我而言,我使用“org.altbeacon:android-beacon-library:2. +”作为库。根据移动设备的不同,蓝牙服务会停止检测。

0 个答案:

没有答案