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?