0

I am trying to get package name of the opened app and I am successful in getting for the app using it but I want to extend this to all apps. I mean to say that whenever someone opens an app from the menu, my app should toast its packagename.

Here is the code I am using:

PACKAGE_NAME = getApplicationContext().getPackageName();

if(isNamedProcessRunning(PACKAGE_NAME)){

    Toast.makeText(this.getBaseContext(), PACKAGE_NAME+" running", Toast.LENGTH_SHORT).show();

}
else{
    Toast.makeText(this.getBaseContext(),"WhatsApp Not running", Toast.LENGTH_SHORT).show();

}

The above should run every time a new activity of any app is opened and should display its packagename in a toast message. How do I do that?

Abhishek Singh
  • 197
  • 1
  • 3
  • 17
  • possible duplicate of [Does Android broadcast when an app is opened?](http://stackoverflow.com/questions/10282365/does-android-broadcast-when-an-app-is-opened) – Kuba Spatny Mar 29 '15 at 21:52

1 Answers1

-1

Search a bit

Does Android broadcast when an app is opened?

How to Track App Usage in Android? How to detect when an activity is launched?

https://stackoverflow.com/help/how-to-ask

Community
  • 1
  • 1
denvercoder9
  • 2,979
  • 3
  • 28
  • 41
  • I searched and those links were not useful. They say its not possible. However, I don't think so. Anything is possible. – Abhishek Singh Mar 29 '15 at 19:34
  • yes it's possible if you hack the source code of a stock android and add the apis necessary – denvercoder9 Mar 29 '15 at 19:54
  • There are apps which allow people to get package name of all the apps and also some battery based apps turn off some apps and regulate them. So its possible without hacking. – Abhishek Singh Mar 29 '15 at 20:38