我遇到了一個問題,那就是這個線程的相反的問題:altbeacon如何讓後臺服務保持活躍狀態?
AltBeacon not detect beacon when app is closed
我有一個使用altbeacon(http://altbeacon.org/)
該應用程序初始化實現接口的altbeacon的應用在應用程序級別如下(詳細內容略)
public class MyApp extends Application implements
BootstrapNotifier,
BeaconConsumer {
//some code
@Override
public void onCreate() {
super.onCreate();
initBeacons();
}
public void initBeacons() {
mBackgroundPowerSaver = new BackgroundPowerSaver(this);
org.altbeacon.beacon.BeaconManager altBeaconManager = org.altbeacon.beacon.BeaconManager.getInstanceForApplication(this);
altBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
// estimote
altBeaconManager.setBackgroundScanPeriod(5000);
altBeaconManager.setBackgroundBetweenScanPeriod(25000);
mBeaconManager = MyBeaconManager.getInstance(this, altBeaconManager);
mRegionBootstrap = new RegionBootstrap(this, MyBeaconManager.getRegions());
altBeaconManager.bind(this);
}
@Override
public void onBeaconServiceConnect() {
Thread thread = new Thread() {
public void run() {
// Try range the beacons
rangeMyBeacons();
}
};
thread.start();
}
@Override
public void didEnterRegion(Region region) {
// Some code
}
@Override
public void didExitRegion(Region region) {
// Some code
}
@Override
public void didDetermineStateForRegion(int i, Region region) {
// Some code
}
public class MyBeaconManager implements
RangeNotifier {
// some code
但是,如果我殺了應用程序或重啓手機,沒有任何特殊的廣播或應用程序alt-beacon服務的權限恢復正常。換句話說,Alt-beacon始終會重新啓動。請注意,我沒有任何前臺服務正在運行。這是幾個小時後的應用程序截圖(我重新啓動了手機),所有應用程序關閉。您可以看到alt-beacon處於活動狀態並掃描信標。
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
LogManager.i(TAG,
intent == null ?
"starting with null intent"
:
"starting with intent " + intent.toString()
);
return super.onStartCommand(intent, flags, startId);
}
我做了庫中搜索,我看到沒有命中START_REDELIVER_INTENT或START_STICKY。
我的問題是如何ALT-燈塔保持服務活着的時候,應用程序被殺害?
我想了解此功能的原因是,我寫了類似的服務,但我只能把它做的工作爲ALT信標,如果我把它包裝成前景的服務。我嘗試過的其他事情,只要應用程序關閉,服務就會被殺死。
謝謝。