Search code examples
androidserviceprocessbroadcastreceiver

Way to get current running foreground app/process


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


Solution

  • 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
                }