android - 谷歌位置 API : request location updates with pending intent?

标签 android location google-api android-pendingintent location-client

我已经开始使用 this tutorial 实现 Google Location API .

我已经设法让它在我的应用程序中正常工作,它会以正确的时间间隔更新我的位置等。现在我正在研究如何在设备处于 sleep 模式时更新我的​​位置。根据documentation , 这种方法是要走的路:

public void requestLocationUpdates (LocationRequest request, PendingIntent callbackIntent);

我的问题是,如何设置此 PendingIntent,以及如何处理它?我看过有关如何处理其他类型 Intent 的教程,但我不确定如何将它们应用到此。

最佳答案

您可以通过挂起的 Intent 注册广播接收器或 Activity 。注册广播接收器的示例:

    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);

您的广播接收器:

public class ProximityIntentReceiver extends BroadcastReceiver {

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

关于android - 谷歌位置 API : request location updates with pending intent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17827121/

相关文章:

android - 弧形矩形机器人

android - 如何在 Android 中的其他应用程序选择器 Intent 中以不同的名称列出我的应用程序

android - 在 android 服务的单独线程中运行位置更新

java - OTP 未从 firebase 代码中获取是正确的

android - 使用 android Picasso 或 Glide 滚动时出现卡顿效果

android - 更改应用程序区域设置后如何获取设备区域设置

android - 是否有任何设计模式可以应用于 Android 位置管理器帮助程序类?

google-analytics - 如何使用 API 提取 Google Analytics 历史数据。优点和缺点?

ruby-on-rails - 使用 Google Ruby Client 处理 oauth 错误?

javascript - 在没有 node.js 的情况下从文件(文件系统)读取