I am curious if there is any way available in Android OS to tell the app that an application is just launched. Basically, in my app I want to notify my app that an application is going to be launched or just launched. On that event, I want to perform some operations like block that application if user(using my application) has included that in block list.Any help or direction will be highly appreciated..
Asked
Active
Viewed 359 times
0
-
use application class for your requirement – Quick learner Oct 01 '19 at 06:49
-
How can application notify me that other installed application is launched o going to launch. Could you please give me little more info about this? – Abdul Waheed Oct 01 '19 at 06:51
-
oh i am mistaken by the fact "other" application i thought own app – Quick learner Oct 01 '19 at 06:52
-
use a background service implement runnable for every second and check the current package thats how you will be able to know what app just launched – Quick learner Oct 01 '19 at 06:53
-
https://stackoverflow.com/questions/25481456/android-lock-application or https://stackoverflow.com/questions/36261909/how-to-make-app-lock-app-in-android Try above solutions – Amin Pinjari Oct 01 '19 at 07:59
1 Answers
1
first Add
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.System.canWrite(context)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, 200);
}
} else {
//Do work
}

Danial clarc
- 724
- 1
- 7
- 25
-
Your method getTopAppName always returns my app running weather that is in foreground or background. I kept that method in service with 3 seconds interval. When I launch other install apps that is returning my app pkg name – Abdul Waheed Oct 01 '19 at 07:24
-
I tried with permission it is popping out a screen that has some google system apps list google play store, services and pxiel launcher. In that list my application is not listed – Abdul Waheed Oct 02 '19 at 10:47
-
I called requestOpsPermission then it is opening Usage access and showing application to allow. It is showing other applications except my appplication. I guess after this permission given I need to call getlollpopFG method right? but why my app is not listed to give permission? – Abdul Waheed Oct 02 '19 at 10:56
-
I tried without permission then getLollipopFGAppPackageName method returning empty string. Anything missing? – Abdul Waheed Oct 02 '19 at 11:04
-
Now I have implemented the way you have mentioned but it is opening Modify System setting screen and there is switch and that is disabled. And that is not letting me enable that switch any help? – Abdul Waheed Oct 02 '19 at 11:28