Notified when an application installed/removed on phone via BroadCastReceiver

Suppose, your application wanna knows when a new application is installed on your phone or an application already in phone is uninstalled. How you notified?
Ya, You can add a BroadcastReceiver in your manifest or java code. Then check the system broadcast message android.intent.action.PACKAGE_REMOVED & android.intent.action.PACKAGE_ADDED when an app is uninstall & install respectively. Follow me to do the trick.
Create a Class MyReceiver Which extends BroadcastReceiver and override it's onReceive method. Then check your desired system broadcast message.

 package com.codeandcoder.tutorial;  
   
 import android.content.BroadcastReceiver;  
 import android.content.Context;  
 import android.content.Intent;  
 import android.util.Log;  
 import android.widget.Toast;  
   
 public class MyReceiver extends BroadcastReceiver {  
   
      Context context;  
   
 @Override  
 public void onReceive(Context context, Intent intent) {  
   
      this.context = context;  
   
      // when package removed  
  if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) {  
      Log.e(" BroadcastReceiver ", "onReceive called "  
                          + " PACKAGE_REMOVED ");  
      Toast.makeText(context, " onReceive !!!! PACKAGE_REMOVED",  
                          Toast.LENGTH_LONG).show();  
   
           }  
    // when package installed  
  else if (intent.getAction().equals(  
                     "android.intent.action.PACKAGE_ADDED")) {  
   
      Log.e(" BroadcastReceiver ", "onReceive called " + "PACKAGE_ADDED");  
      Toast.makeText(context, " onReceive !!!!." + "PACKAGE_ADDED",  
                          Toast.LENGTH_LONG).show();  
   
           }  
      }  
 }  

Register this broadcast receiver in manifest. Add below code to manifest.

 <receiver  
    android:name="MyReceiver"  
    android:enabled="true"  
    android:priority="0" >  
   <intent-filter>  
     <action android:name="android.intent.action.PACKAGE_ADDED" >  
     </action>  
     <action android:name="android.intent.action.PACKAGE_REMOVED" >  
     </action>  
     <data android:scheme="package" />  
   </intent-filter>  
  </receiver>  

After you run your activity or app, the broadcast receiver is registered and waiting to listen when a package/app is installed or uninstalled & notify you.. :)