I am creating an application that can periodically receive a location using NETWORK_PROVIDERin the background without using GPS_PROVIDER. I use ALARM_SERVICEand WakeLock( PARTIAL_WAKE_LOCK). but the problem I am facing is that the Internet connection is disconnected after turning off the screen. when I unlock the phone, I start to get the location, but when the screen turns off, I get no place.
It's because:
- The Internet connection is suspended after turning off the screen, and also when I unlock the screen, I receive USSD code messages for using data, does this mean that my Internet connection is disconnected after turning off the screen?
- Although the Internet connection is turned on, the location is not updated in the background because the screen is off.
I use the GpsTracker class to get the location from here and periodically using the AlarmManager location. also in class LatLongBroadcastReceiveri get 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);
source
share