如何接收位置更新,而无需使用服务位置

由网友(※妹,哥的肩膀给你靠)分享简介:时有替代运行的服务,以接收位置更新吗?Is there an alternative to running a service to receive location updates?推荐答案您可以使用一个PendingIntent这样的 - You could use a PendingIntent lik...

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

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

阅读全文

相关推荐

最新文章