use*_*716 7 android location geofencing android-geofence
我正在尝试使用Google的示例测试地理围栏功能:创建和监控地理围栏.我在这里上传了代码.
问题是我从未收到进入或退出的通知.我有Wifi,4G和GPS.我试过用以下方法测试:
我究竟做错了什么?ANyone成功运行了这个谷歌的例子:创建和监控地理围栏.我在这里上传了代码以便于浏览.
我只是想学习Geofencing - 检测进入和退出.我将标记任何答案作为我可以用来在我的真实设备上进行地理工作的正确答案
.
小智 17
我也遇到了示例代码的问题.我遇到的一个主要问题是声明ReceiveTransitionsIntentService.您不需要添加BroadcastReceiver或请求位置更新,但您需要更改AndroidManifest以将导出值设置为true,如下所示:
<service
android:name=".ReceiveTransitionsIntentService"
android:exported="true" >
</service>
Run Code Online (Sandbox Code Playgroud)
确保服务的路径也正确.
我已经大大简化了Google示例,您可以在此处找到代码和说明.我删除了UI组件和持久的Geofence存储,因此这个示例应该更容易理解.希望这可以帮助!
小智 0
最初我的代码运行顺利,但之后我也遇到了这个问题,请通过修改 continueAddGeofences() 函数中的 geofenceRequester 类来尝试此操作。基本上是通过位置请求方法调用接收者
private void continueAddGeofences() {
// Get a PendingIntent that Location Services issues when a geofence
// transition occurs
mGeofencePendingIntent = createRequestPendingIntent();
// Send a request to add the current geofences
mLocationClient.addGeofences(mCurrentGeofences, mGeofencePendingIntent,
this);
//mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
try {
LocationRequest locationrequest = LocationRequest.create();
locationrequest.setPriority(locationrequest.PRIORITY_HIGH_ACCURACY);
locationrequest.setInterval(3000);
mLocationClient.requestLocationUpdates(locationrequest, mGeofencePendingIntent);
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6088 次 |
| 最近记录: |