android - Is it possible to trigger location change without battery drain? -
in application need update user's location when entering city.
so example:
- user lives in citya
- user travels citya cityb
- a function should triggered.
i see following functions provided google play services:
public abstract location getlastlocation (googleapiclient client)
public abstract pendingresult<status> requestlocationupdates (googleapiclient client, locationrequest request, locationlistener listener)
the problem is:
i need track user's city location changes continuously, not when user using app.
how without draining battery fast?
you can use broadcast receivers this. there documentation @ https://developer.android.com/reference/android/content/broadcastreceiver.html.
private static final locationrequest request = locationrequest.create() .setfastestinterval(60000) // in milliseconds .setinterval(180000) // in milliseconds .setpriority(locationrequest.priority_low_power);
'@override public void onconnected(bundle bundle) { locationservices.fusedlocationapi.requestlocationupdates( mgoogleapiclient, request, this); // locationlistener }`
use fusedlocationapi , go.
Comments
Post a Comment