我正在运行 Android 4.3 的三星 Galaxy Tab 2 上使用 Radius Networks iBeacon SDK 的 Pro 版本进行开发。该应用程序已经成功使用非专业版 0.7 一个月了,但我想要后台事件,所以我去了专业版 1.0。AndroidProximityLibrary 项目是 Eclipse 中的一个项目依赖,ProximityKit.properties
文件位于src/
.
以下代码是我的 Application 子类,如文档中所述。该应用程序具有 BLUETOOTH 和 BLUETOOTH_ADMIN 权限。从 LogCat 输出中注意到,在didDetermineStateForRegion()
按预期进入睡眠后未调用该方法。必须改变什么才能在后台发生一些事情?
我见过一个类似的问题,叫做RadiusNetworks 库的 iBeacon 背景扫描 PRO feature?但是那里的问题似乎正在调用IBeaconManager.unbind()
,导致操作系统清理服务。我的代码从不调用IBeaconManager.unbind()
,只有IBeaconManager.bind()
.
public class ExampleApp extends Application implements BootstrapNotifier, IBeaconConsumer {
private static final String LOG_TAG = ExampleApp.class.getName();
private RegionBootstrap regionBootstrap;
private IBeaconManager iBeacon;
private Region region;
public ExampleApp() {
String uuid = "EBEFD083-70A2-47C8-9837-E7B5634DF520";
region = new Region("com.example.ble", uuid, null, null);
}
@Override
public void onCreate() {
super.onCreate();
iBeacon = IBeaconManager.getInstanceForApplication(this);
iBeacon.setBackgroundBetweenScanPeriod(10000);
iBeacon.setBackgroundScanPeriod(3000);
iBeacon.bind(this);
regionBootstrap = new RegionBootstrap(this, region);
}
@Override
public void onIBeaconServiceConnect() {
Log.d(LOG_TAG + ".onIBeaconServiceConnect", "connected to iBeacon service");
try {
iBeacon.startRangingBeaconsInRegion(region);
} catch (RemoteException e) {
String msg = "caught exception while enabling beacon ranging";
Log.e(LOG_TAG + ".onIBeaconServiceConnect", msg, e);
}
}
@Override
public void didEnterRegion(Region region) {
Log.d(LOG_TAG + ".didEnterRegion", "YEAH ENTERED");
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
Log.d(LOG_TAG + ".didDetermineStateForRegion", "YEAH STATE");
Intent intent = new Intent(this, LaunchActivity.class);
startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
@Override
public void didExitRegion(Region region) {
Log.d(LOG_TAG + ".didExitRegion", "YEAH EXITED");
}
}
我在信标范围之外运行应用程序,然后走进范围。30 秒后什么都没有发生,所以我按下电源按钮仍然没有任何反应。我把电话插上,从亚行那里得到了踪迹。
LogCat 在睡眠(家庭然后电源)和 30 秒后唤醒(电源)之间的 INFO 级别
05-28 14:05:23.456: I/PowerManagerService(2392): [ps] Screen__Off(0) : goToSleepFromNative: (uid: 1000 pid: 2392)
05-28 14:05:23.456: I/PowerManagerService(2392): Going to sleep by user request...
05-28 14:05:23.471: W/KeyguardViewMediator(2392): wakeUpIfNeeded() mMaybeShow=true mRequestedWakeUp=false mShowing=false
05-28 14:05:23.516: E/SEC PowerHAL(2392): sysfs_write : Error opening /sys/class/input/input11/enabled: No such file or directory
05-28 14:05:23.516: E/SEC PowerHAL(2392): sysfs_write : Error opening /sys/class/input/input1/enabled: No such file or directory
05-28 14:05:23.516: E/SEC PowerHAL(2392): sysfs_write : Error opening /sys/class/input/input10/enabled: No such file or directory
05-28 14:05:23.521: I/libsuspend(2392): !@[s] autosuspend_earlysuspend_enable : 40
05-28 14:05:23.521: I/libsuspend(2392): !@[s] wait_for_fb_sleep : 40 (1, 0) -
05-28 14:05:23.521: I/libsuspend(2392): !@[s] autosuspend_earlysuspend_enable done : 40
05-28 14:05:23.521: I/libsuspend(2392): !@[s] wait_for_fb_wake : 40 (0, 0) +
05-28 14:05:23.521: I/PowerManagerService(2392): [PWL] Off : 0s ago
05-28 14:05:23.521: I/PowerManagerService(2392): [PWL] PowerManagerService.WakeLocks: ref count=1
05-28 14:05:23.521: I/PowerManagerService(2392): [PWL] PowerManagerService.Broadcasts: ref count=1
05-28 14:05:23.521: I/PowerManagerService(2392): [PWL] mWakeLockSummary : 0x1
05-28 14:05:23.521: I/PowerManagerService(2392): [PWL] PARTIAL_WAKE_LOCK 'ActivityManager-Sleep' (uid=1000, pid=2392, ws=null) (elapsedTime=42)
05-28 14:05:23.526: I/CAE(2392): onReceive(CaPowerManager.java:142) - AP_SLEEP
05-28 14:05:23.531: I/CAE(2392): sendCmdToSensorHub(SensorHubCommManager.java:146) - -76, 13, -46, 0,
05-28 14:05:23.561: I/CAE(2392): parse(SensorHubParserProvider.java:136) - buffer size = 3
05-28 14:05:23.561: I/CAE(2392): parse(SensorHubParserProvider.java:147) - 2, 1, -46,
05-28 14:05:23.591: I/AudioHardwareTinyALSA(1989): setParameters(screen_state=off)
05-28 14:05:23.591: I/audio_wfd_hw(1989): adev_set_parameters() screen_state=off
05-28 14:05:23.616: I/NfcService(2909): # NativeNfcBrcmPowerMode; setPowerMode(android.intent.action.SCREEN_OFF)
05-28 14:05:23.621: E/NfcService(2909): callback == null
05-28 14:05:23.691: I/AutoBackupUtil(9627): checkAutoBackupCondition returns : false
05-28 14:05:23.691: I/AutoBackupUtil(9627): bChargerConnected : true
05-28 14:05:23.691: I/AutoBackupUtil(9627): bWifiConnected : false
05-28 14:05:23.691: I/AutoBackupUtil(9627): bScreenOn : false
05-28 14:05:24.871: I/SurfaceFlinger(1986): id=996 Removed Uoast (5/6)
05-28 14:05:24.871: I/SurfaceFlinger(1986): id=996 Removed Uoast (-2/6)
05-28 14:05:28.526: I/PowerManagerService(2392): [PWL] Off : 5s ago
05-28 14:05:38.541: I/PowerManagerService(2392): [PWL] Off : 15s ago
05-28 14:05:51.251: E/Watchdog(2392): !@Sync 8274
05-28 14:05:53.556: I/PowerManagerService(2392): [PWL] Off : 30s ago
05-28 14:05:55.986: E/BatteryService(2392): Could not open /efs/FactoryApp/batt_cable_count
05-28 14:05:56.081: E/Sensors(2392): Light old sensor_state 0, new sensor_state : 64 en : 1
05-28 14:05:56.096: I/SensorService(2392): info.selectDelay() ns=200000000
05-28 14:05:56.101: I/PowerManagerService(2392): [ps] Screen__On(wake lock) : wl: charger plug
05-28 14:05:56.101: I/PowerManagerService(2392): Waking up from sleep...
05-28 14:05:56.126: I/libsuspend(2392): !@[s] autosuspend_earlysuspend_disable : 41
05-28 14:05:56.151: I/KeyguardBackgroundView(2392): *** KeyguardEffectView getInstance ***
05-28 14:05:56.151: I/WindowManager(2392): No lock screen!
05-28 14:05:56.196: I/NfcService(2909): # NativeNfcBrcmPowerMode; setPowerMode(android.intent.action.USER_PRESENT)
05-28 14:05:56.266: E/videowall-TranscodeReceiver(10819): broadcastMSG : android.intent.action.ACTION_POWER_CONNECTED
05-28 14:05:56.276: I/EntropyMixer(2392): Writing entropy...
05-28 14:05:56.281: E/Sensors(2392): Light old sensor_state 64, new sensor_state : 0 en : 0
05-28 14:05:56.326: I/CAE(2392): onReceive(CaPowerManager.java:150) - POWER_CONNECTED
05-28 14:05:56.326: I/CAE(2392): sendCmdToSensorHub(SensorHubCommManager.java:146) - -76, 13, -42, 0,
05-28 14:05:56.426: E/Launcher(2928): Error finding setting, default accessibility to not found: accessibility_enabled
05-28 14:05:56.536: I/SSRMv2:Monitor(2392): fileWriteInt : /sys/class/power_supply/battery/siop_level value : 100
05-28 14:05:56.546: E/Sensors(2392): Light old sensor_state 0, new sensor_state : 64 en : 1
05-28 14:05:56.556: I/SensorService(2392): info.selectDelay() ns=200000000
05-28 14:05:56.556: E/Sensors(2392): Light old sensor_state 64, new sensor_state : 0 en : 0
05-28 14:05:56.556: E/MotionRecognitionService(2392): mReceiver.onReceive : ACTION_USER_PRESENT :: UNLOCK SCREEN
05-28 14:05:56.571: E/BatteryService(2392): Could not open /efs/FactoryApp/batt_cable_count
05-28 14:05:56.576: I/libsuspend(2392): !@[s] wait_for_fb_wake : 41 (1, 0) -
05-28 14:05:56.576: I/libsuspend(2392): !@[s] wait_for_fb_sleep : 41 (0, 0) +
05-28 14:05:56.576: I/libsuspend(2392): !@[s] autosuspend_earlysuspend_disable done : 41
05-28 14:05:56.576: E/SecTVOutService(1986): virtual void android::SecTVOutService::setHdmiStatus(uint32_t)::mSecHdmi.connect() fail
05-28 14:05:56.576: E/SEC PowerHAL(2392): sysfs_write : Error opening /sys/class/input/input11/enabled: No such file or directory
05-28 14:05:56.576: E/SEC PowerHAL(2392): sysfs_write : Error opening /sys/class/input/input1/enabled: No such file or directory
05-28 14:05:56.576: E/SEC PowerHAL(2392): sysfs_write : Error opening /sys/class/input/input10/enabled: No such file or directory
05-28 14:05:56.616: I/CAE(2392): onReceive(CaPowerManager.java:146) - AP_WAKEUP
05-28 14:05:56.616: I/CAE(2392): sendCmdToSensorHub(SensorHubCommManager.java:146) - -76, 13, -47, 0,
05-28 14:05:56.681: I/AudioHardwareTinyALSA(1989): setParameters(screen_state=on)
05-28 14:05:56.681: I/audio_wfd_hw(1989): adev_set_parameters() screen_state=on
05-28 14:05:56.796: E/SELinux(11287): Function: selinux_android_load_priority [0], There is no sepolicy file
05-28 14:05:56.796: E/SELinux(11287):
05-28 14:05:56.801: E/SELinux(11287): Function: selinux_android_load_priority , loading version is VE=SEPF_GT-N7105_4.3_0021
05-28 14:05:56.801: E/SELinux(11287):
05-28 14:05:56.801: E/SELinux(11287):
05-28 14:05:56.801: E/SELinux(11287): selinux_android_seapp_context_reload: seapp_contexts file is loaded from /data/security/spota/seapp_contexts
05-28 14:05:56.821: I/NfcService(2909): NFC: When Screen On, S View Cover also Open!!
05-28 14:05:56.821: I/NfcService(2909): # NativeNfcBrcmPowerMode; setPowerMode(android.intent.action.SCREEN_ON)
05-28 14:05:56.841: I/CAE(2392): parse(SensorHubParserProvider.java:136) - buffer size = 3
05-28 14:05:56.841: I/CAE(2392): parse(SensorHubParserProvider.java:147) - 2, 1, -47,
05-28 14:05:56.871: I/ActivityManager(2392): Killing proc 11287:com.sec.android.SimpleWidget/u0a10145: force stop com.sec.android.SimpleWidget
05-28 14:05:56.886: W/ActivityManager(2392): Permission denied: checkComponentPermission() owningUid=10029