1

I am looking for a way to listen for starting applications/activities. I guess many of You know the application "Tasker" which achieves exactly that. If a chosen applications gets launched, a specific task starts.

Now I wonder how to achieve that? I could start a Service, but which method should I use?

I noticed that Tasker asks for a permission before using this method. The application redirects me to the Accessibility Settings tab where I can enable Tasker with the notification: "Tasker wants permission to: Monitor your actions - Allows TalkBack to know when you are using an app"

Any suggestions?

Edit:

I found out that an AccessibilityService is used. Now my problem is, how do I specify all installed packages to this Service? I know that it's possible to specify packages one by one but how do I select all?

user2410644
  • 3,861
  • 6
  • 39
  • 59

1 Answers1

0

you can use getRunningTasks Method

ActivityManager am = (ActivityManager) mContext
            .getSystemService(Activity.ACTIVITY_SERVICE);
    String packageName = am.getRunningTasks(1).get(0).topActivity
            .getPackageName();

Note This method was deprecated in API level 21. you can try this also.

Community
  • 1
  • 1
Kishan Vaghela
  • 7,678
  • 5
  • 42
  • 67