背景BLE触发器使用Radius Networks Pro iBeacon SDK

时间:2014-05-28 06:19:45

标签: android ibeacon ibeacon-android android-ibeacon

我正在使用运行Android 4.3的三星Galaxy Tab 2上的Pro版Radius Networks iBeacon SDK进行开发。该应用程序已成功使用非专业版0.7一个月,但我想要背景事件,所以我去了Pro 1.0版。 AndroidProximityLibrary项目是Eclipse中的项目依赖项,ProximityKit.properties文件位于src/

以下代码是我的Application子类,如documentation中所述。该应用程序具有BLUETOOTH和BLUETOOTH_ADMIN权限。请注意,LogCat输出中按预期进入睡眠状态后未调用didDetermineStateForRegion()方法。需要改变什么来在后台发生一些事情?

我看到一个类似的问题叫iBeacon background scanning PRO feature of RadiusNetworks library?,但问题似乎是调用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在INFO级别之间睡眠(Home然后电源)和30秒后唤醒(电源)

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

2 个答案:

答案 0 :(得分:1)

使用RegionBootstrap时,您无需致电iBeacon.bind(this);,也不需要onIBeaconServiceConnect()的实施。这是因为这些任务由RegionBootstrap类在内部处理。

要解决此问题,请尝试将您的手动电话转至iBeacon.bind(this);

答案 1 :(得分:0)

解决方案是在调用setBackgroundBetweenScanPeriod()setBackgroundScanPeriod()后致电IBeaconManager.updateScanPeriods()。由于我的代码没有这样做,Radius SDK仍然以默认间隔扫描(在后台10分钟)。