android-location
Change Location Mode to High Accuracy Programmatically Android
It is possible to get the device’s current location mode since API level 19 (Kitkat): public int getLocationMode(Context context) { return Settings.Secure.getInt(activityUnderTest.getContentResolver(), Settings.Secure.LOCATION_MODE); } These are the possible return values (see here): 0 = LOCATION_MODE_OFF 1 = LOCATION_MODE_SENSORS_ONLY 2 = LOCATION_MODE_BATTERY_SAVING 3 = LOCATION_MODE_HIGH_ACCURACY So you want something like if(getLocationMode(context) == 3) { // do … Read more
Error adding geofences in Android (status code 1000)
You get GEOFENCE_NOT_AVAILABLE (code ‘1000’) when user disagrees to “Use Google’ location services” in Settings->Location->Mode: To fix it: go to Settings->Location->Mode set “Device only (Use GPS to determine your location)” set any other option to get the popup (e.g. “High accuracy (Use GPS, Wi-Fi and mobile networks to determine location”) dialog “”Use Google’ location services” … Read more
Why is FusedLocationApi.getLastLocation null
The fused location provider will only maintain background location if at least one client is connected to it. Now just turning on the location service will not guarantee storing the last known location. Once the first client connects, it will immediately try to get a location. If your activity is the first client to connect … Read more
Minimal android foreground service killed on high-end phone
A service started by startForeground belongs to the second most important group visible process: A visible process is doing work that the user is currently aware of, so killing it would have a noticeable negative impact on the user experience. A process is considered visible in the following conditions: It is running an Activity that … 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