不要Geofences设备重启后继续活跃在安卓 [英] Do Geofences remain active in android after a device reboot

查看:400
本文介绍了不要Geofences设备重启后继续活跃在安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写,需要使用地理围栏当有人进入一个应用程序/退出要安装多个站点在应用程序的生命周期。

I'm writing an application that needs to use geofencing for when someone enters/exits multiple sites over the lifetime of the application being installed.

我的执行地理围栏(非常类似于下面的第二个链接)是所有工作正常,当我第一次安装应用程序,无论是在/出geofences的移动和使用模拟地点时,模拟它,直到设备重新启动时, 。

My implementation of geofencing (very similar to the second link below) is all working fine when I first install the application, both when moving in/out of the geofences and when using mock locations to simulate it, until a device is rebooted.

在重启既不模拟地点,也没有实际的物理进出地理栅栏似乎触发事件和火灾挂起意图,我的广播接收器。

On reboot neither mock locations nor actually physically moving in and out of a geofence appears to trigger the event and fire the pending intent to my broadcast receiver.

我已经看过了以下三个环节,也看过不少的DOC的,但我无法找到一个明确的答案,这任何地方,直上说,注册geofences持续或重新引导后不会继续存在。

I have looked at the following three links and have also read quite a bit of the doc's but I can't find a definitive answer to this anywhere that straight up says registered geofences persist or do not persist after a reboot.

这些都是我的堆栈溢出审查的链接: 是Android的geofences尚存重新启动?

These are the links I reviewed on stack overflow: Are Android geofences surviving a reboot?

<一个href="http://stackoverflow.com/questions/19505614/android-geofence-eventually-stop-getting-transition-intents?answertab=active#tab-top">Android地理栅栏最终停止得到转变的意图

<一个href="http://stackoverflow.com/questions/17829976/do-android-geofences-remain-active-until-removed-expired-or-only-until-my-pendin">Do Android的Geofences仍然有效,直到删除/到期或只有等到我PendingIntent启动

如果有人碰巧知道答案,他们围绕是否重启后粘,或周围有一个工作,如果他们不这样做,这将是更AP preciated!我最后的希望目前正在建立一个监听器BOOT_COMPLETED并重新注册他们在启动时,但ID preFER在绝对必要时只做到这一点。

If anyone happens to know the answer to whether they stick around post reboot, or has a work around if they do not, it would be much appreciated! My last hope currently is to create a listener for BOOT_COMPLETED and re-register them on start up but id prefer to only do this if absolutely necessary.

感谢很多提前!

编辑:虽然我还没有找到一个明确的(书面)回答,我是pretty的知道TonyC先生发布是正确的,并且都选择了该解决方案。非常感谢TonyC!

Whilst I have not found a definitive (in writing) answer, I am pretty sure what Mr. TonyC posted is correct, and have opted for that solution. Thanks a lot TonyC!

在万一有人希望看到的解决方案,我有,我听当一个设备引导的引导完整的动作,然后重新注册所有我需要的geofences。

In case anyone wants to see the solution I have, I listen for the boot complete action when a device is booted, and then re-register all the geofences I need.

这是在清单:

<!-- Listen for the device starting up -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<receiver android:name="com.YOUR.PACKAGE.geofence.BootCompleteReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
    </intent-filter>
</receiver>

,然后创建一个广播接收器为它这将重新注册引导geofences:

and then create a broadcast receiver for it which will re-register the geofences on boot:

package com.YOUR.PACKAGE.geofence;

import android.app.PendingIntent.CanceledException;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.location.Geofence;

public class BootCompleteReceiver extends WakefulBroadcastReceiver
{
    private static final String TAG = "BootCompleteReceiver";

    @Override
    public void onReceive(Context context, Intent intent)
    {
        //Do what you want/Register Geofences
    }
}

另外值得一提的是,如果你是在引导地理栅栏里面,这通常会再触发栅栏的悬而未决的意图,一旦栅栏已被注册。

It's also worth noting, that if you are inside a geofence on boot, this usually will then trigger the geofence's pending intent once the geofence has been registered.

所以,如果例如,地理栅栏启动一个应用程序,那么当你开机出现这种情况是在地理栅栏设备,它也会打开应用程序一旦启动完成广播接收器已注册了地理围栏,和位置服务曾出在哪里。

So if for instance, the geofence starts an app, then when you boot a device that happens to be in the geofence, it will also open the app once the boot complete broadcast receiver has registered the geofence, and location services has worked out where you are.

希望这是一些帮助的人。

Hope that is some help to someone.

推荐答案

在我的经验,geofences没有生存重启。我使用的是BOOT_COMPLETED接收器就像你的建议。它工作正常。

In my experience the geofences do not survive reboot. I use a BOOT_COMPLETED receiver just as you suggest. It works fine.

这篇关于不要Geofences设备重启后继续活跃在安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆