相关疑难解决方法(0)

如何在Android中使Geo Fencing警报更准确

您好我正在尝试在Android中添加Geo Fence的功能.我正在使用http://developer.android.com/training/location/geofencing.html来创建和监控Geo Fences.我正在使用IntentService警报(已输入/退出),但对我来说它不起作用.

但是当我离开并回到地区测试它然后它对我不起作用.我已打开设备的GPS,但设备未与互联网连接.

任何人都可以帮助我让它更准确,更完美,没有任何问题.

public class MainActivity extends Activity implements GooglePlayServicesClient.ConnectionCallbacks,
        GooglePlayServicesClient.OnConnectionFailedListener,
        LocationClient.OnAddGeofencesResultListener {

    private LocationClient locationClient;

    private String TAG = "MainActivity";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        int resp = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        if (resp == ConnectionResult.SUCCESS) {
            locationClient = new LocationClient(this, this, this);
            locationClient.connect();
        }
    }

    @Override
    public void onConnected(Bundle bundle) {
        ArrayList<Store> storeList = getStoreList();
        if (null != storeList && storeList.size() > 0) {
            ArrayList<Geofence> geofenceList = new ArrayList<Geofence>();
            for (Store store …
Run Code Online (Sandbox Code Playgroud)

android geofencing google-play-services android-geofence

9
推荐指数
1
解决办法
8903
查看次数

应用程序被杀死时的 Android 地理围栏

我的主要要求是让服务拥有自己的流程并触发自己的地理围栏事件。我希望用户在进入地理围栏时收到通知中心的通知,即使应用程序被终止。

我读过服务,这对我来说似乎很清楚,Android 文档很密集,所以我设法了解如何使用自己的进程启动服务,以及它如何使用 Messenger 与应用程序通信。

然后是来自 Google 的此代码示例,展示了如何将地理围栏与 google play 服务一起使用: Google 示例地理围栏

到目前为止,我发现我们必须使用 IntentService 来触发地理围栏事件,并且从我读过的文档中可以看出,IntentService 在其工作完成后会自行终止。而且我也进行了一些测试,看起来 Intentservice 在应用程序被杀死时被杀死,这对文档来说并不让我感到惊讶。

所以我的问题是,我们如何执行具有自己流程的地理围栏服务?在这件事上可以避免使用 IntentService 吗?

编辑:

我想这样做的原因是用户可以设置地理围栏“提醒”,它基于日常使用。例如,假设您每天到达工作场所,当我们进入此地理围栏时,我们应该能够发出警报(或通知),以了解应用程序是否正在运行。我们不希望用户担心应用程序在后台运行。

service android android-service geofencing android-geofence

5
推荐指数
1
解决办法
3617
查看次数