Created
January 13, 2014 18:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<receiver android:name=".LocationReceiver" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LocationReceiver extends BroadcastReceiver { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
Location location = (Location) intent.getExtras().get(LocationClient.KEY_LOCATION_CHANGED); | |
} | |
} |
please send me too :(
Thanks for the post, that seems to be more efficient.
Please send full source code I'm Facing Same Problem
can someone provide the full source with all the dependencies and includes?
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
I'm facing the same problem after implementing Location Service in My application. Can u pls upload or send me full source code.