BroadcastReceiver for location

I think what you are looking for is something like this. There is a version of LocationManager.requestLocationUpdates() that takes a PendingIntent as a parameter, and this Intent could be used to fire a BroadcastReceiver. This code will register a custom broadcast to fire with the location updates. Intent intent = new Intent(“UNIQUE_BROADCAST_ACTION_STRING_HERE”); LocationManager manager = … Read more

Enabling Location mode High Accuracy or Battery saving, programmatically, without user needing to visit Settings

UPDATE 3: Prompt the user to change location settings as @patrickandroid, mentioned in comments, the link from second update is broken GoogleSamples; android Location and options – for code reference. UPDATE 2: GoogleSamples; – for code reference. This sample builds on the LocationUpdates sample included in this repo, and allows the user to update the … Read more

How to get the current location latitude and longitude in android

Before couple of months, I created GPSTracker library to help me to get GPS locations. In case you need to view GPSTracker > getLocation Demo AndroidManifest.xml <uses-permission android:name=”android.permission.INTERNET” /> <uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” /> Activity import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.TextView; public class MainActivity extends Activity { TextView textview; @Override protected void onCreate(Bundle savedInstanceState) { … Read more

Background service with location listener in android

First you need to create a Service. In that Service, create a class extending LocationListener. For this, use the following code snippet of Service: public class LocationService extends Service { public static final String BROADCAST_ACTION = “Hello World”; private static final int TWO_MINUTES = 1000 * 60 * 2; public LocationManager locationManager; public MyLocationListener listener; … Read more

How to get current location in Android [duplicate]

First you need to define a LocationListener to handle location changes. int LOCATION_REFRESH_TIME = 15000; // 15 seconds to update int LOCATION_REFRESH_DISTANCE = 500; // 500 meters to update …. private final LocationListener mLocationListener = new LocationListener() { @Override public void onLocationChanged(final Location location) { //your code here } }; Then get the LocationManager and … Read more