新的Android Geofence API - 示例代码在位置时不会提醒/通知 [英] New Android Geofence Api - Sample code does not alert/notify when at location

查看:273
本文介绍了新的Android Geofence API - 示例代码在位置时不会提醒/通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



/location/geofencing.htmlrel =nofollow> https://developer.android.com/training/location/geofencing.html



I运行代码,我发现geofences是正确创建的,但我真正想要的是当我开车到那些地理位置相同的位置时获得警报的方式。现在,当我经过那些地理围栏点时,什么也没有发生(ReceiveTransitionsIntentService不会被调用),没有任何通知。

我是否还必须定期更新位置信息并手动将lat / lng传递给上述代码以指示我当前的位置?我认为这应该是自动的,当我将地理围栏添加到LocationClient,但我想还有更多。



我也尝试将LocationRequest注册到LocationClient实例,但仍然没有提醒:

  mLocationRequest = LocationRequest.create(); 
mLocationRequest.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS);

mLocationClient.requestLocationUpdates(mLocationRequest,(LocationListener)mActivity);

如何将Geofence API与位置跟踪集成?

解决方案

我也有问题。将服务添加到您的AndroidManifest时,请确保您的路径已正确定义。我还必须将导出的值更改为true。

 < application> 
...
< service
android:name =。ReceiveTransitionsIntentService
android:exported =true>
< / service>
...
< / application>

您还需要在Manifest中添加元数据标记来指定您的Google gms版本。

 < application> 
...
< meta-data
android:name =com.google.android.gms.version
android:value =4242000/>
...
< / application>

我已经创建了一个更简单的Google示例版本,包含代码和更多解释, here 。希望有帮助!


I need some clarity on the sample code supplied with Geofence guide as posted here :

https://developer.android.com/training/location/geofencing.html

I ran the code and I see that geofences are created correctly, but what I really want is a way to get alerted when I drive to those geofenced locations. Right now, when I go past those geofenced spots, nothing happens (ReceiveTransitionsIntentService does not get called), no notifications nothing.

Do I also have to listen to periodic location updates and pass lat/lng to the above piece of code manually to indicate my current location? I thought this should be automatic when I add geofences to LocationClient, but I guess there is more.

I also tried registering a LocationRequest to the LocationClient instance, but still no alerts :

mLocationRequest = LocationRequest.create();
mLocationRequest.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS);

mLocationClient.requestLocationUpdates(mLocationRequest, (LocationListener)mActivity);

How does one integrate Geofence api with location tracking?

解决方案

I also had issues. Make sure your path is defined correctly when adding the service to your AndroidManifest. I also had to change the exported value to true.

<application>
...
    <service
        android:name=".ReceiveTransitionsIntentService"
        android:exported="true" >
    </service>
...
</application>

You also need to add the meta-data tag in your Manifest to specify your google gms version.

<application>
...
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="4242000" />
...
</application>

I've created a much simpler version of the Google example, with code and more explanation, here. Hope that helps!

这篇关于新的Android Geofence API - 示例代码在位置时不会提醒/通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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