How to check if an external app is running on foreground? - android

I am trying to build an application in which a service can check whether an external application is running at foreground or not.
For example, when we enter in Google Chrome, this service automatically detects what package has been executed and reacts in one way or another.
It's that even possible?
I have heard about 'getRunningTasks' method but is deprecated on new Android versions
Any suggestion is appreciated.

Related

Android Oreo: Is there any way to auto - start the application on mobile reboot?

I am developing an application for a business entity. That application should run in the background in every employees' mobile phone. Employees are mostly salesman. The application basically detects location changes and suggest the salesman where they might visit. A kind of reminder application. It also lets other salesmen see where are their teammates.
Right now I am using a foreground activity and it works fine till the system forcefully doesn't kill the service or the phone doesn't reboot due to manual activity or battery discharge.
Ones the application is closed, as of now, the managers in the firm needs to call salespeople to turn on the application once, as on application start it automatically turn on its foreground service. But this is really an extra burden on the management team which can be automated.
I am ok to have any settings based or code based solution. One solution is to root the phones of salespeople and install some extra utility app or write the code based on root APIs, but this will be too much for this simple task.
THe permission RECEIVE_BOOT_COMPLETED was not added properly in the manifest. After adding the permission it worked calmly. In on receive method of the broadcast receiver, I am starting the foreground service.
At the moment, the best way is to use WorkManager https://developer.android.com/topic/libraries/architecture/workmanager/ Yes, it still alpha, but works very good.
From other side, you could work on automating the task "managers in the firm needs to call salespeople to turn on the application once". I mean, an app/backend could automatically call the salesman (with some pre-recorded message) or send SMS to them.

Can we create an apk without an user interface in android

I want to create an apk, without an user interface in android. And I need to start a Service as soon as the Applicaton gets installed on the Device. Is there any possible way to create an apk without UI.
Thanks in advance.
And I need to start a Service as soon as the Applicaton gets installed on the Device.
Fortunately, that is not possible for an app installed through normal channels (e.g., the Play Store), for security reasons, since Android 3.1. Nothing of your app will run until something on the device uses an explicit Intent to start up one of your components, and that most certainly does not occur when your app is installed.
You are welcome to build your hardware, or your own custom ROM, that has your app pre-installed. In that case, you can arrange to be able to run right away.
yes, you have juste to create a Service or a BrodcastReceiver which do something you want

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.

What's the mechanism of locking access to selected applications in Android?

I'm trying to find out how applications like Perfect App Protector or Smart Applock Free work.
What mechanism is used?
These applications use a service to monitor whether a new application is trying to launch or not.
It can be done in several ways. If running application matched with the configured application then it is sent back to the background by the service and may ask for lock code, password as you configured earlier. If it matches then you will get the application on the foreground. Otherwise it kills the process from being executed.

Detect if an app was uninstalled

Is there a way to get a system notification when an app has been uninstalled?
I would like to maintain a table of all clients' info currently using my app. However, that seems impossible if there is no way to detect this event.
The first solution I can think of is to have an always running service in the background listening for android.intent.action.PACKAGE_REMOVED. But then would that service be killed once the uninstallation process has ended, or would it be stopped just before the process has kicked off? Also even if this is a solution it's has the potential to put off a lot of people when they realise that part of the app is running in the background.
Any suggestions? Thanks!
You could simply do it the other way round and maintain a table of users actively using your app. Just call a webservice at a point in the program that show it is active. If an app isn't used for a certain time mark it as inactive.
The documentation for the PACKAGE_REMOVED action says the following:
The package that is being uninstalled does not receive this Intent.
So you can monitor for other applications being uninstalled but not your own.
So you'll probably need track who is still using your application, not who has stopped using it. If you don't want the overhead of having your own server to do this you could use a free service like Flurry.
From Android document, the app uninstalled by user can't not get
Intent.ACTION_PACKAGE_REMOVE
But we can use other method to implement this feature. We all know that there is a directory named with your package name under the /data/data directory after your app installed by user. If your app is uninstalled by user, the root directory of your app(/data/data/com.example.yourappname) will be removed by system. The remove action happen immediately when user click "uninstall", and the directory will be removed by framework package manager system.
So, we can monitor the existence of your app data directory(which usually /data/data/com.example.yourappname) to detect if your app uninstalled by user.
In order to monitor this directory, we have to fork a detached process from JNI.
In this new fork process, we can use Linux system api inotify(7) or access(3) to determine the existence of app's data directory.
Here is a workable implementation. But it got the permission problem when try to send an intent to start system browser on high version Android device. I have no idea how to bypass this. However the example above is enough for your question.
Hope it will be helpful!
Android doesn't provide an inbuilt function for tracking the app uninstall.
Notification can be used as an alternate way to track the app uninstall. For this send notification on the app and track the status of the notification. Count the number of undelivered notification for a particular time period. If status of undelivered notification doesn't change in that particular time period, then consider that the app has been uninstalled from the device.
For example, i have used a cron script which run every 3 days and check the status of last 10 notifications delivered to the device (2 notifications are sent in a day). If all of these 10 notifications have status "undelivered", then the app is considered to be uninstalled from the device.

Categories

Resources