如何接收位置更新,而无需使用服务 [英] How to receive location updates without using a service

查看:170
本文介绍了如何接收位置更新,而无需使用服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时有替代运行的服务,以接收位置更新吗?

Is there an alternative to running a service to receive location updates?

推荐答案

您可以使用一个PendingIntent这样的 -

You could use a PendingIntent like this -

Intent intent = new Intent(CUSTOM_INTENT);
    LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    PendingIntent launchIntent = PendingIntent.getBroadcast(context, 5000, intent, 0);

    manager.requestLocationUpdates(selectProvider(), 0, 0, launchIntent);

您广播接收器应该在清单文件的意图过滤器的CUSTOM_INTENT

Your broadcast receiver should have an intent filter for the CUSTOM_INTENT in the manifest file

这篇关于如何接收位置更新,而无需使用服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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