I am building application which can get location using NETWORK_PROVIDER
periodically in background without using GPS_PROVIDER
. I am using ALARM_SERVICE
and WakeLock
(PARTIAL_WAKE_LOCK
). but the problem which i am facing is that internet connection gets disconnected once the screen goes off. when I unlocks the phone I starts receiving the location, but when the screen goes off I am not getting the locations.
Is it because:
- Internet connection gets paused once the screen goes off and also when I unlocks the screen I get the USSD code messages of Data Usage, so does it means my internet connection goes off once the screen goes off?
- Even though the internet connection is on but location doesn't gets updated in background as the screen is in off state.
I am using GpsTracker class to get location from here and using AlarmManager get location periodically. also in LatLongBroadcastReceiver
class i am fetching a location.
Intent intent = new Intent(GPSlatlongActivity.this,
LatLongBroadcastReceiver.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
pendingIntent = PendingIntent.getBroadcast(
GPSlatlongActivity.this.getApplicationContext(), 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime(),
(AlarmManager.INTERVAL_FIFTEEN_MINUTES / 15),
pendingIntent);