How to know that app has been paused in Android Q? - android

Is there any callback that the app has been paused in Android Q?
I'd like to do some actions with the app in such a case, but I can't find any descriptions of it.
"Pause app" is a new feature of Android Q:
https://9to5google.com/2019/05/21/digital-wellbeing-pixel-launch-pause-app/
It's not onPause() lifecycle method.

For other users downvoting his question - this is about a feature in Google's Digital Wellbeing program which has been pushed to Pixel phones - not about the activity lifecycle
For OP - I don't think you will get a satisfactory answer to this yet. I have looked through the Android Q Beta documentation and they are not offering links to anything specific. However for developers in the future, I think the term to search for is "distraction state" as mentioned in their docs:
Per-app distraction state -- Android Q can now selectively set apps to a "distraction state" where their notifications are suppressed and they will not appear as suggested apps.
For now the only thing I can suggest is to not target android Q in gradle. So today the correct answer is this information / api has not been made public yet

As currently there's no official documentation for this issue, I'm posting this as an answer with hope there will be the official solution.
You can register a BroadcastReceiver with intent filter Intent.ACTION_PACKAGES_SUSPENDED. It will be triggered once you put the app to this mode.
But I'm not sure it won't have side effects or will work stable on all devices. I tried it on Pixel 2.

Currently at the time of this post. There is no documentation regarding Android Q Pause App feature in relation to Android Activity Lifecycle and how to apps can track this action. But based on my understanding of how Pause App feature works from the post i read here is that, all notifications from the app are disabled and also selection of the app from the launcher is also disabled.
App paused using Pause App feature can still be running but can
neither be resumed/launched nor send new notifications.
Here is my take on what i think the paused app can do to verify that it is paused when targeting android Q. Though not efficient enough.
App starts a notification during launch using startForeground so it won't be dismissed by the user. Showing something like MyApp is running.
App uses a running foreground service which regularly checks the state of the notification every nth minutes.
If the service is still running and the foreground notification is closed or cannot be found by the service then logically we can say that the app is in a paused state.

Related

Reopen my Flutter app in background on FCM message

all day I already despair of a waking up system for my VoIP app. I must have already read over 100 articles and documentation about it, however I have not found a solution that works for me.
Use case:
My app is running in the background. That means the home button was pressed
after my app was started and the device is in the home screen. As soon as a notification arrives, the app is supposed to open again on a certain route because a call is coming in.
In the lock screen I managed this pretty easily with flutter_local_notifications and within the app it was of course no problem either.
Note:
Only Android is important, the rest can be neglected
Android version 10+
Flutter version 2+
I appreciate any input on how to solve my problem and have a good week.
Kind regards,
Shiro

How to check if Google Maps is running in the background?

I have Google Maps installed on my phone and it is usually fully stopped, because I don't want it to always run in the background, since I believe that it is draining the phone battery.
My question is regarding the actual status of the Google Maps app or service.
If you check an app's info there is a button "Force stop". I believe that it is only activated (meaning you can click it) when the app is somehow running.
I noticed that the Google Maps app seems to get started in some way from time to time in the background, because the button gets enabled regularly.
However there is no such entry in the "Running" section for the list of apps in the android settings.
Does someone know whether it is running or not if the button is enabled? Is there some way to check this by code? Is it supposed to be a service or an app?
I have tried using the getRunningAppProcesses and getRunningServices methods of the ActivityManager class, but can't find any entry that would correspond to the Google Maps app. So I guess it is hidden from the user?!
This link may answer your question as to what is the proper way of getting the apps running in background. It suggests that using getRunningAppProcesses and getRunningServices methods are unreliable. Instead, you have to track the visibility of your app on your own via Activity.onPause() and Activity.onResume().

android IncomingHandler not fired when we close the application by removing from recent list

I am writing a sample application for detecting iBeacons through android app. I am using the code from the following site https://github.com/AlvinBert/android-ibeacon-Jaalee-source-code
With the code from the above site i can able to detect ibeacons and send notifications. When i check the running apps, there is 1 Service running.
If i close my application, by long press the home key and remove my app from the Recent list, then i didn't get the notifications, but still 1 service is running.
I debug the code and found that "IncomingHandler" is not getting fired which is in the service inside the "com.communicate.ibeacon.service.IBeaconService" package.
I need this to be called continuously, even after the application closes. Since, i am new to android could you please point me what to do, to achieve this.
Thanks
Jai
The beacon library you mention is an unauthorized copy of the Pro Android iBeacon Library formerly provided by Radius Networks. As the original author of that library, I can confirm that it would not detect beacons after the app being killed until a power cycle of the phone takes place. Unfortunately, this library had been discontinued by my company over licensing issues.
Library issues aside, one approach you could take to accomplish your goal is to use Androud Broadcast Intents to automatically re-launch your app based on system events like power connected and disconnected. This will not relaunch immediately, but will typically do so once a day when a device is in normal use.

programmatically temporarily disable auto-update

I have a Bike computer app that logs data while the user is riding. I have had a user report an issue I had not considered. He was out for a long ride (100+ miles) but while out and logging data the app got updated via Google plays auto-update. This unfortunately killed off the app mid recording and the user lost data till they spotted what had happened and restarted the app.
Ideally I would like to be able to programmatic stop the auto-update happening while the app is data logging. All my research indicates that this is not possible possible but I may of missed something so dose anyone know of a way of doing this?
Given no solution the best I can do is advice the users to enable the update only over wifi option in the Play app which in this instance would of helped. Unfortunately one of the key points about my app is that it will log indoor sessions using ANT+ sensors so I have a good number of people using it with wifi active.
Edit
I managed to do the experiment to see what happens myself last night. I had an app going in the background data logging then pushed a new version to Google Play. Unfortunatly it was not picked up totaly automaticaly when I had to leave 10 hours latter but I opened up the play store app and it found the update it did not start updating automaticaly but I forced it. The act of downloading and installing the new version killed off what was in progress. It was already dead before I used the notification to go to the new version.
As you say yourself, you can't do that what you are asking for. You could hack your way around it by changing the permissions each time you update. The users will then be prompted about it in the regular way.
I'm not sure about the "life-cycle" for automatic updated apps that are running. But I read somewhere that is wasn't the re-install but the reopen of the app that crashed it. If that is the case you could set a flag indicating that the user is currently logging and then on restart just resume the logging. But again we need to know more about the inner workings of activities/apps which are running and get an automatic update (actually didn't think it could happen).
Edit
Based on your findings I'd say you have to handle the app is shut down in onDestroy etc. or/and make sure you save everything persistently. Then you might need to have 2 apps where 1 listens to the other being re installed and when that happens it starts it up again (there is an interesting discussion here). If you are targeting api >= 12 then the broadcast action ACTION_MY_PACKAGE_REPLACED might also have interest.

How to Lock(Block) an android application from starting / How to stop an android application (service) from starting at boot

I would like to know if there is a way to lock (prevent) an application from starting.
And i also would like to know if there is a way to prevent a service(application) from starting at boot of the device
...i would like to know because i would like to create an anti-malware app.
I know this question is old, but for others stumbling over it:
Autostarts is an application that can disable apps from starting at boot time. It's the best I've found to do that (it isn't resident and doesn't kill processes like a task manager, it actually parses apk packages and reads registered actions and blocks the actions you tell it to). BUT it needs root and hasn't been updated for a while (december 2011). It works on Android 2.3 on which I tested it. Because it was discontinued, I don't know if it works on newer OS versions.
It's commercial now, but that's not the point, you need a peek at the source code.
If you search a bit, you'll be able to find the source code for an older version and see how it implements the blocking system.
I would be very interested in an application that could block certain services. NOT kill, but prevent them from starting in the first place. And the list is quite big: Facebook (OrcaService, MqttPushService, MediaUploadService, BackgroundDetectionService), Twitter, Maps (NetworkInitiatedService), Yahoo Mail Sync, etc. I don't use the features that the services provide, I even disabled some of them in the app interface where possible, but they still pop up and remain resident after exiting the application.
I would like to know if there is a way to lock (prevent) an application from starting.
Not in any supported fashion. Anything that does this is malware, and the techniques for doing it are security holes.
And i also would like to know if there is a way to prevent a service(application) from
starting at boot of the device
The user can boot their phone in safe mode (I forget the exact process, but it's something like holding down the HOME key while turning the phone on).

Categories

Resources