Skip to content Skip to sidebar Skip to footer

How To Get Location Object Every 10 Minutes In Android

please someone give me a code can recover the GPS position or every n minutes, I tested several code but no result Please someone give me a tutorial or a small program for that, I'

Solution 1:

This can be answered in 2 parts.

  • calling a background service every 10 mins, using alarm
  • Using a LocationManager and LocationListener, choosing between (or both) network and gps provider. If chose network provider, since gps provider takes a hell a long time to connect and I dont need the accuracy of gps. Network provider is accurate upto 250ms (i got 1 bad sample in 5 hours). Keep in mind LocationListener, does not work on Samsung phones (since samsung phones have heavily customized build of Android, and they dont do a thorough job of porting).

OR

  • I used a force get my location now kinda call God.locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)

In addition to the alarm code above, put the following code in the onHandleIntent

@OverridefinalprotectedvoidonHandleIntent(Intent intent) {
    mainContext = getApplicationContext() ;
    Location myLocation;
        if (God.locationManager == null)
            God.locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        myLocation = God.locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (myLocation != null)
            onLocationChanged(myLocation);
        else {
            God.notifications.setSpeedNotification();
        }
}

Note : You can choose LocationManager.GPS_PROVIDER, just be ready to test it under open sky (no clouds) and about 5 mins to sync with 4-5 satellites.

Post a Comment for "How To Get Location Object Every 10 Minutes In Android"