Is there any way in Java where if I run my Java app in background and whenever I click on some App, I can get the name of it.
This Java program should run in background without the knowledge of the user and will send the app name to a remote server.
Is there any way in Java where if I run my Java app in background and whenever I click on some App, I can get the name of it.
This Java program should run in background without the knowledge of the user and will send the app name to a remote server.
While I question the motives for this, this won't be possible within the bounds of the Java API. You would need to use JNI to interface with the underlying OS, or make calls to an external program that could provide you with these details.
I wrote a time-tracker app that does something similar back in the day, to track how I was spending time on various projects/applications, etc. The idea was to track my application usage locally, and use a POST request to a web server for centralized logging. I could also run this app on any machine I wanted, and the POST request would still go back to a central server, so I could track my own activity across multiple machines.
One thing you could use is JNI to bind to the Win32 API, which can then give you access to Window titles, process information, etc.
This Q/A should get you started: How can I read the window title with JNI or JNA?
Somewhere (I can't find it right now) there's a .JAR on the net that wraps the win32 API, making this sort of functionality very simple to do in Java.