I am trying to subscribe to location updates via Google\'s FusedLocationProviderApi. I want to receive updates in the background, so that I will receive updates even if the app
Remove the extras from the pending intent, otherwise the location result is not delivered. I can't find where in the documentation this is explained but I found out after lot of trial and error.
You can use:
int id = 7;
String name = "myName";
uriBuilder.scheme("http")
.authority("workaround.com")
.appendPath("extra")
.appendQueryParameter("id", String.valueOf(id))
.appendQueryParameter("name", name);
intent.setData(uriBuilder.build());
and
@Override
protected void onHandleIntent(Intent intent) {
if (LocationResult.hasResult(intent)) {
int id = Integer.valueOf(uri.getQueryParameter("id"));
String name = uri.getQueryParameter("name");
....
}
}
A workaround (Christophe Beyls suggested that only Intent Data should be used) So, since I only need to send a few parameters, so I do something like this: while building the Intent before the requestLocationUpdates: intent.setData(Uri.parse("http://a.com/a?"+ Param1+ "?" + Param2+ "?" + Param3); and in the BroadcastReceiver: String[] parameters = intent.getDataString().split("[?]"); This works fine, and intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED) does return the location.