1

i want to set receiver when ever any application get launched in android,after that i have to do some task.is there any way to do?

 @Override
public void onReceive(Context context, Intent intent) {
    try {

    } catch (Exception e) {

    }

}

I have to set this receiver,when ever any application launched....

1 Answers1

0

As far as I understand, you want to receive a broadcast whenever any application is launched. Unfortunately, there's no intent that is fired by the system for this, so it's not possible to receive a broadcast when any other application is launched. Though, you can determine the currently running application using ActivityManager and ComponentInfo (Google it, though this method will only work for pre-L devices, as Android L has removed this in view of increasing security). Hope this helps.

gaurav jain
  • 3,119
  • 3
  • 31
  • 48
  • We appreciate your answer but doing in such way we have to do pooling in order to find the active activity all the time, which drains the battery. Usage Access can't check the active Activity? – Duna Dec 11 '18 at 09:12