When Android device boot up, my application will start working in the foreground. User can put my application to background and he\she can use other applications for a desired long time.
When user stop interaction with phone for 30 seconds or lock the phone, my application will (if required)unlock the phone and continue to become active in the foreground.
How can achieve this?
User can put my application to background and he\she can use other
applications for a desired long time.
Starting from Android O you won't be able to reliably make your app work in background. System applies several restrictions on background processing especially running background services. Only alternative would be to create Foreground Service. But if OS detects that you are performing CPU intensive work this won't work either.
When user stop interaction with phone for 30 seconds or lock the
phone, my application will (if required)unlock the phone and continue
to become active in the foreground.
Unfortunately its not possible. Even if manage to get Administrator rights there is no API which allows developers to unlock the phone without user's action. This would be a privacy breach.
Related
I am using service for sending current location of device to server continuously in background, but service is also getting killed when I swipe out the application on some phones. It's working if I remove restriction of running background services from Phone settings to the app. I will be thankful, If someone provide solution of removing this restriction programatically.
Every Phone manufacturer has it's own settings for background processing apps. As there are many android device manufacturers it will be difficult to check for every device group. I'm facing the same issue for my app. It will be better if you ask to check is there any setting regarding background services in their device.
I have an open source gps tracking application that has been around for many years. Recently, I have been getting complaints that in android nougat, instead of getting updates once a minute, people are getting updates from the phone once every five minutes when the phone is unplugged.
There is something going on with the power saver mode even though we tried turning it off.
Is there a way to force a phone to get gps updates at a specified time when unplugged?
Here is the code if anyone wants to see it but I don't think it's a problem with the code. It has been very stable for years.
https://github.com/nickfox/GpsTracker/blob/master/phoneClients/android/app/src/main/java/com/websmithing/gpstracker/LocationService.java
thanks.
One change in Android 7/Nougat was that the Doze is now "more aggressive". In Android 6/Marshmallow the doze mode kicked in when the screen was off, the device was running on battery and it was stationary.
(This is documented in Optimizing for Doze and App Standby)
Now in Android 7 the conditions are just screen off and running on battery.
(This is documented in Android 7.0 Behavior Changes)
Apps can be white-listed to be exempt of the restrictions if they break the core functionalility of it. In your case they do as the GPS tracker needs to record coordinates in real time.
There's a list of Acceptable Use Cases for Whitelisting
This includes:
Task automation app | App's core function is scheduling automated
actions, such as for instant messaging, voice calling, new photo
management, or location actions.
Users can white list an app manually on their own in the device settings or whitelisting can be requested by the app and approved or rejected by the user.
This is covered in Support for Other Use Cases
Quoting:
An app can fire the ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS intent
to take the user directly to the Battery Optimization, where they can
add the app.
An app holding the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission can
trigger a system dialog to let the user add the app to the whitelist
directly, without going to settings. The app fires a
ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Intent to trigger the
dialog.
The user can manually remove apps from the whitelist as needed.
The last point is important of course, but luckily the whitelisting status can be checked programmatically:
An app can check whether it is currently on the exemption whitelist by
calling isIgnoringBatteryOptimizations().
So, dealing with the Doze mode is one thing to study at least.
Another issue is keeping the Service running in general. But the Service getting killed by the system might result in more random time intervals. There are of course the classic things like using START_STICKY or running as a foreground service.
I am running an accelerometer based android app that will run for a few months while phone is on and does nothing else. Some phone allow display not to go to sleep at all which allows my app run fine infinitely. The screen also has only a black display and nothing else apart from background accelerometer listener and occasional http posts. My question is if I remove the display screen while the app is running, would that stop the operating system and/or my app?
My question is if I remove the display screen while the app is running, would that stop the operating system and/or my app?
In short, it depends on your app architecture (otherwise i.e. music players would require to keep screen on to work). Depending on task you are really doing you may use Alarm Manager to periodically fire your code, or use Service.
On the Android Market there is an app called Sleep Timer, and it is a type of alarm clock that brings runs the alarm even though you locked your phone while on facebook. I made a type of app that detects movement however it only works if the phone is left on that app... How can I make it work when the app wasn't left upfront, but is still running in the background?
You should take a look at Android Services, which provide the functionality you seek. Basically they enable you to create components that run in the background even when the user switch away from your application.
You can find a very good introduction to them here: http://developer.android.com/guide/components/services.html
I want my app to keep running when the screen is blank and locked.
This is an instrumentation app that runs when the phone is in the pocket, so we can blank the screen to save power.
Currently:
If the phone locks automatically the screen goes blank and the app terminates. When the phone is unlocked the app needs to be re-started.
If the phone is manually locked (with a tap on the power button) the screen goes blank, the app stays running, but the data to voice output stops "working". When the phone is unlocked the app is still running and the data to voice starts "working" again.
I don't think WakeLock will do that for me. It's a function that's more like a sticky bit, as in load and don't terminate unless there is a specif command to terminate.
Any pointers to what I should be doing would be appreciated - thanks - Rob
Why don't you start a 'Service' that your Activity's can bind to. This can run even when your App isn't.
http://developer.android.com/reference/android/app/Service.html
A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.
Imagine how a mp3 playing application works, same scenario.