What you are looking for is called Broadcast Reception. This technology is available to all developers and it is designed to "listen to" all the events occurring in the Android system. The topic is extensive, and if you are not familiar with it, then this is bad. Be sure to check out!
There are a huge number of events that you can "catch" and handle. Among them are those that you need:
This event is broadcast by the system itself when installing a new APK. By registering your own broadcast receiver in the manifest, you can respond to this system action. You can read more about usage here , for example.