谷歌位置API:请求位置更新与待决意图? [英] Google location API: request location updates with pending intent?

查看:213
本文介绍了谷歌位置API:请求位置更新与待决意图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用本教程

我已经设法使它在我的应用程序中工作得很好,它以正确的时间间隔更新我的位置等。现在我正在研究如何当设备处于睡眠模式时更新我的​​位置。根据文档,此方法是要走的路:

  public void requestLocationUpdates(LocationRequest request,PendingIntent callbackIntent); 

我的问题是,如何设置PendingIntent,以及如何处理它?我已经看过如何处理其他类型的意图的教程,但我不知道如何将它们应用于此。 解决方案

您可以通过等待意向注册Broardcast Reciever或Activity。示例注册boardcast接收者的示例:

  String proximitys =ACTION ; 
IntentFilter filter = new IntentFilter(proximitys);
registerReceiver(mybroadcast,filter);
意图意图=新意图(接近度);
PendingIntent proximityIntent = PendingIntent.getBroadcast(this,0,
intent,PendingIntent.FLAG_CANCEL_CURRENT);
locationManager.requestLocationUpdates(provider,mintime,mindistance,
proximityIntent);

您的Broardcast Reciever:

  public class ProximityIntentReceiver extends BroadcastReceiver {

@SuppressWarnings(deprecation)
@Override
public void onReceive(Context arg0,Intent intent){
//要执行的动作
}


I have started to implement the Google Location API using this tutorial.

I've managed to get it to work in my application quite fine, it updates my location at the right intervals etc. Now I am working on how to update my location when the device is in sleep mode. According to the documentation, this method is the way to go:

public void requestLocationUpdates (LocationRequest request, PendingIntent callbackIntent);

My question is, how do I set up this PendingIntent, and how do I handle it? I've seen tutorials of how to handle other types of intent, but I am not sure how to apply them to this.

解决方案

You can either register Broardcast Reciever or Activity through pending intent.Sample Example for registering boardcast reciever:

    String proximitys = "ACTION";
    IntentFilter filter = new IntentFilter(proximitys);
    registerReceiver(mybroadcast, filter);
    Intent intent = new Intent(proximitys);
    PendingIntent proximityIntent = PendingIntent.getBroadcast(this, 0,
            intent, PendingIntent.FLAG_CANCEL_CURRENT);
    locationManager.requestLocationUpdates(provider, mintime, mindistance,
            proximityIntent);

Your Broardcast Reciever:

public class ProximityIntentReceiver extends BroadcastReceiver {

    @SuppressWarnings("deprecation")
    @Override
    public void onReceive(Context arg0, Intent intent) {
           //action to be performed
    }

这篇关于谷歌位置API:请求位置更新与待决意图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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