【问题标题】:IBeacon getting warning Implcit intents are not safe on callback of MonitorNotifierIBeacon 在 MonitorNotifier 回调时收到警告隐含意图不安全
【发布时间】:2014-04-18 10:48:09
【问题描述】:

我正在使用 Android 4.4 并在找到具有指定区域的信标时在 Monitoring 的回调中收到警告消息。

我用于监控的代码是

@Override
public void onIBeaconServiceConnect() {

    iBeaconManager.setMonitorNotifier(new MonitorNotifier() {
        @Override
        public void didEnterRegion(Region region) {
          Log.e("didEnterRegion","I just saw an iBeacon for the first time!");       
        }

        @Override
        public void didExitRegion(Region region) {
            Log.e("didExitRegion","I no longer see an iBeacon");
        }

        @Override
        public void didDetermineStateForRegion(int state, Region region) {
            Log.e("didDetermineStateForRegion","I have just switched from seeing/not seeing iBeacons: "+state);   

            if(state == MonitorNotifier.INSIDE){
                try {
                    //Start Ranging in the Region.
                    iBeaconManager.startRangingBeaconsInRegion(region);
                } catch (RemoteException e) { 
                    System.out.println(e);
                }

            }
            else if(state == MonitorNotifier.OUTSIDE){
                try {
                    //Stop Ranging in the Region.
                    iBeaconManager.stopRangingBeaconsInRegion(region);
                } catch (RemoteException e) { 
                    System.out.println(e);
                }

            }
        }
        });

        try {
            //Start Monitoring in the Region.
            iBeaconManager.startMonitoringBeaconsInRegion(region);
        } catch (RemoteException e) { 
            System.out.println(e);
        }

我在 logcat 中发现的警告信息是

04-19 14:32:08.156: D/BluetoothAdapter(10564): startLeScan(): null 
04-19 14:32:08.166: D/BluetoothAdapter(10564): onClientRegistered() - status=0 clientIf=5 
04-19 14:32:08.176: D/IBeaconService(10564): Scan started 
04-19 14:32:08.186: D/IBeaconManager(10564): Got a ranging callback 
04-19 14:32:08.186: D/IBeaconManager(10564): Got a ranging callback with 0 iBeacons 
04-19 14:32:08.186: D/IBeaconManager(10564): Calling ranging notifier on :com.example.ranging.BackgroundRanging$4@4226f1e8 
04-19 14:32:08.787: D/BluetoothAdapter(10564): onScanResult() - Device=4A:92:06:A9:FA:87 RSSI=-52 
04-19 14:32:08.787: D/IBeaconService(10564): got record 
04-19 14:32:08.797: D/IBeacon(10564): calculating accuracy based on rssi of -52.0 
04-19 14:32:08.797: D/IBeaconService(10564): iBeacon detected :128f4e13-01ef-4618-bffa-50fed67f24aa 1001 3003 accuracy: 0.47659904336004005 proximity: 1 
04-19 14:32:08.797: D/Callback(10564): attempting callback via intent: com.example.service.DID_MONITORING 
04-19 14:32:08.807: W/ContextImpl(10564): Implicit intents with startService are not safe: Intent { act=com.example.service.DID_MONITORING (has extras) } android.content.ContextWrapper.startService:494 com.radiusnetworks.ibeacon.service.Callback.call:85 com.radiusnetworks.ibeacon.service.IBeaconService.processIBeaconFromScan:438  
04-19 14:32:08.817: D/IBeaconService(10564): looking for ranging region matches for this ibeacon 
04-19 14:32:08.817: D/IBeaconService(10564): matches ranging region: proximityUuid: 128f4e13-01ef-4618-bffa-50fed67f24aa major: null minor:null 
04-19 14:32:09.257: D/IBeaconService(10564): Done with scan cycle 
04-19 14:32:09.257: D/IBeaconService(10564): Calling ranging callback with 1 iBeacons 
04-19 14:32:09.257: D/Callback(10564): attempting callback via messenger 
04-19 14:32:09.257: D/IBeaconService(10564): Restarting scan.  Unique beacons seen last cycle: 1 
04-19 14:32:09.257: D/BluetoothAdapter(10564): stopLeScan() 

【问题讨论】:

  • 你能发布你的代码和确切的警告信息吗?
  • @davidgyoung ,请查看编辑。

标签: ibeacon-android android-ibeacon


【解决方案1】:

此警告出现在 Android iBeacon 库的过时版本(0.7 或更早版本)中。最新版本是0.7.6,不会有这个警告。简单的解决方案是简单地升级到可用库的最新版本here.

该警告与 iBeacon 数据在库的后台服务和您的应用程序之间传递的方式有关。该库的早期版本使用“隐式意图”来传递此信息,如果手机上同时使用该库的两个应用程序,理论上可能会导致 iBeacon 数据发送到错误的应用程序。出于开发目的,这并不重要,但如果在生产应用中使用它,您应该使用最新的库版本。

【讨论】:

  • 大卫与最新的图书馆我面临一个新问题。在范围通知回调中,我正在调用我的应用程序的一个方法,并且通过此升级,我必须在 UI 线程中调用该方法,否则它会给我异常,即 [code]android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created一个视图层次可以触摸它的视图。[code]我只升级了库,旧版本的库没有这个错误。
  • 我是 stackoverflow 的新用户,我正在尝试改进文本的格式。
  • 嗨,@Dheeresh,请为此提出一个新问题,因为这是一个不相关的问题。
  • @Vrajesh,更新后的下载地址为:altbeacon.github.io/android-beacon-library/download.html
猜你喜欢
  • 1970-01-01
  • 2021-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-28
相关资源
最近更新 更多