0

I want to get notification whenever application is going to be uninstall, I have googled but I have used this method in BroadCastReceiver class

 public void onReceive(Context ctx, Intent intent) {
    Uri data = intent.getData();
    Log.d("TAG", "Action: " + intent.getAction());
    Log.d("TAG", "The DATA: " + data);


    if (intent.getAction (). equals ("android.intent.action.PACKAGE_ADDED")) {
        String packageName = intent.getDataString ();
        System.out.println ("installed:" + packageName + "package name of the program");
        Toast.makeText(ctx, "installed:" + packageName + "package name of the program", Toast.LENGTH_LONG).show();
        }
        if (intent.getAction (). equals ("android.intent.action.PACKAGE_REMOVED")) {
        String packageName = intent.getDataString ();
        System.out.println ("uninstall:" + packageName + "package name of the program");
        Toast.makeText(ctx, "uninstall:" + packageName + "package name of the program", Toast.LENGTH_LONG).show();  
        }
    }

and adding in Android Manifest class

<receiver android:name="PackageChangeReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED" />
                <action android:name="android.intent.action.PACKAGE_REPLACED" />
                <action android:name="android.intent.action.PACKAGE_REMOVED" />

                <data android:scheme="package" />
            </intent-filter>
        </receiver> 

But When I install application then it shows message but when we uninstalled application then it doesn't show message. Someone is suggesting to use rooting for it but I am confused I don't have idea of how to make root device programmatically ?

My Question is:- 1. How to show message whenever we uninstall the application from device ? 2. If it is possible without using rooting device please guide me or provide some method or code. 3. If rooting device is only possible way then please help me how to implement it ?

Thanks in advance

Ash
  • 682
  • 2
  • 10
  • 20

2 Answers2

1

Applications cannot be notified of their own package being removed.

Strictly in terms of app developers, there is no way around this. You would need something else on the device besides the app being uninstalled, which you could only do if the device is rooted or if you built a custom ROM. If you are going to be distributing your app to the general public, you will have no way whatsoever to enforce such criterion on the end user's device.

Karakuri
  • 38,365
  • 12
  • 84
  • 104
0

Applications are not notified when an app is uninstalled but notified at the time of installation. To install an application at the time of another app installation, use this in your onReceive() method

if (intent.getAction (). equals ("android.intent.action.PACKAGE_ADDED")) {
            String packageName = intent.getDataString ();
            System.out.println ("installed:" + packageName + "package name of the program");
            Toast.makeText(ctx, "installed:" + packageName + "package name of the program", Toast.LENGTH_LONG).show();


    File apkfile = new File(your_apk_file_path_here);
            if (!apkfile.exists()) {
                return;
            }
            Intent installIntent = new Intent(Intent.ACTION_VIEW);
            installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            installIntent.setDataAndType(
                    Uri.parse("file://" + apkfile.toString()),
                    "application/vnd.android.package-archive");
            startActivity(installIntent);
    }
Sripathi
  • 1,760
  • 15
  • 20
  • This is not answer to question. – trante May 22 '14 at 20:06
  • @trante I already told Ashutosh that its not possible to trace the uninstallation of the app and possible to trace the installation. He asked me the way to install a new app programmatically when installing another app. We deleted that conversation from the comments. Here I answered to add a new app at the time of installing another app. – Sripathi May 23 '14 at 04:05