如何在不使用服务的情况下接收位置更新

时间:2011-06-22 21:05:15

标签: android

是否有其他方法可以运行服务来接收位置更新?

1 个答案:

答案 0 :(得分:5)

您可以像这样使用PendingIntent -

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的意图过滤器