Skip to content

Instantly share code, notes, and snippets.

@katmitchell
Created January 13, 2014 18:25
Show Gist options
  • Save katmitchell/8405403 to your computer and use it in GitHub Desktop.
Save katmitchell/8405403 to your computer and use it in GitHub Desktop.
Background Location Updates in Android - a fix for https://gist.github.com/blackcj/20efe2ac885c7297a676
<receiver android:name=".LocationReceiver" />
@Override
public void onConnected(Bundle bundle) {
Intent intent = new Intent(this, LocationReceiver.class);
PendingIntent locationIntent = PendingIntent.getBroadcast(getApplicationContext(), 14872, intent, PendingIntent.FLAG_CANCEL_CURRENT);
mLocationClient.requestLocationUpdates(mLocationRequest, locationIntent);
...
}
public class LocationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Location location = (Location) intent.getExtras().get(LocationClient.KEY_LOCATION_CHANGED);
}
}
@nishanth2059
Copy link

I'm facing the same problem after implementing Location Service in My application. Can u pls upload or send me full source code.

@ruska-
Copy link

ruska- commented Jun 14, 2014

please send me too :(

@maniankara
Copy link

Thanks for the post, that seems to be more efficient.

@waqary705
Copy link

Please send full source code I'm Facing Same Problem

@dlj23
Copy link

dlj23 commented Sep 16, 2015

can someone provide the full source with all the dependencies and includes?

@ComfortC
Copy link

If you wanted to extract the result being send by the broadcaster you would have to use the Extract result like so

LocationResult result = LocationResult.extractResult(intent);
if(result!=null){
Toast.makeText( context, String.valueOf(result.getLastLocation().getLatitude()),Toast.LENGTH_LONG).show();
Toast.makeText(context, String.valueOf(result.getLastLocation().getLongitude()), Toast.LENGTH_LONG).show();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment