开发者

How to receive location updates without using a service

开发者 https://www.devze.com 2023-03-15 05:18 出处:网络
Is there an alternative to running a service to receive location u开发者_如何学运维pdates?You could use a PendingIntent like this -

Is there an alternative to running a service to receive location u开发者_如何学运维pdates?


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消