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

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().

Related

I need to prevent users from altering settings of my app

I want to prevent users altering settings of my app by throwing up a splash screen to block interactions whenever they go into the device settings and open the settings page for my app.
Here's a video of another app that does this: https://inversatechnosoft.com/wp-content/uploads/2021/03/WhatsApp-Video-2021-03-05-at-7.40.24-AM.mp4
This isn't possible (at least for apps that aren't part of the system image), for good reason: that's the sort of thing malware does to take over a system.
Even if you could do that, that isn't sufficient: an app could also be uninstalled from the launcher, or other apps. You could make it harder through various tricks, but ultimately the user could simply reboot the device into safe mode and do it there.
The only cases where you could have this level of control are managed devices or within a work profile.
I don't think there is an incredibly clean way to do this, but you could start a service which regularly checks the foreground task.
You can then use the ActivityManager to get a list of all running app processes with ActivityManager.getRunningAppProcesses() and then check their importance against IMPORTANCE_FOREGROUND.

Can I get the current app in foreground on current android versions?

With the current versions of Android: Is there still a way to get any hint which application is currently in the foreground (e.g. package name)?
You can't query this information in any Android version, but if you make an accessibility service, you will be notified every time any window is displayed in the foreground, and will be able to determine what package it belongs to.
Note, the user would have to enable your service in settings for this to work, and your app may not be accepted to Google Play store if you abuse this feature.

How to prevent android app from updating from the google play store?

I have an android app that is published in the Google Play Store. The Google Play Store app is how end-users install updates. I realize it's up to the user's discretion to turn on auto-updates, so this feature may or may not be turned on with any given phone.
My app runs a foreground service with an icon in the notification bar when it's running. During testing of the auto-update procedure, I noticed that if the service is running and the app updates itself, the service is shutdown (which is to be expected since new code is being installed).
However, I would like to avoid this if at all possible. What I would like to happen is find a way to detect when auto-update tries to update my app. If the service is running, I'd like to deny updates until the service finishes it's work and shuts down.
So is there any way to detect when the google play store attempts to update your app, and if so, is there a way to block the update until you determine your app is in a safe state to shutdown?
Unfortunately, I don't think there is a way to detect when the Play Store attempts to update your app, unless you have a second app to listen for this event. And even if you have a way to detect this, I don't think you can cancel the update.
Maybe it would be an idea for you to transfer the work you are doing to your second app while the first one is being updated. However, I needn't say that this sounds like a very hacky solution.
You should focus on saving your state and continuing from where you left after the application is updated and started.

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