We are creating a solution for the fleet industry. The app required the device location to be fetched and send all the time, even if the device is locked. we tried the following approaches
- we have enabled the following permissions
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
- On app start created a foreground service and pushed it into the notification panel.
- in the foreground service we are calling
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 0, this);
- on the
OnLocationChanged
we are updating the notification panel with the current location to check if it is working or not.
The app works fine when the device is active. but when the device went to sleep after the screen is locked, the application was terminated by the OS. We tested it in android 9. Is this the correct approach?