Implicit intent to uninstall application?

32,006

Solution 1

First of all, note that the ACTION_UNINSTALL_PACKAGE is only availible to android-14 (i.e. Ice Cream Sandwich, Android 4.0). That said, the following code works for me:

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.view.View;
import android.net.Uri;
import android.content.Intent;

public class TestActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView view = (TextView)findViewById(R.id.test_view);
        view.setOnClickListener(new View.OnClickListener(){
          public void onClick(View view){
            Uri packageUri = Uri.parse("package:org.klnusbaum.test");
            Intent uninstallIntent =
              new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
            startActivity(uninstallIntent);
          }
        });
    }
}

If you want to be able to do this on all versions of the android platform, just change the intent from Intent.ACTION_UNINSTALL_PACKAGE to Intent.ACTION_DELETE like @goto10 does.

Solution 2

Try ACTION_DELETE instead. That's what this example suggests.

EDIT: I just tested this myself and it worked great.

Share:
32,006

Related videos on Youtube

benbeel
Author by

benbeel

Amateur programmer, professional physician

Updated on July 09, 2022

Comments

  • benbeel
    benbeel almost 2 years

    I am trying to have an onclicklistener call an intent to uninstall an app, by having the intent call the default "uninstall app" activity from the applications settings. I have found here that I can uninstall an app using ACTION_UNINSTALL_PACKAGE, com.packageXYXY, which seems to be what I'm looking for. However, I am unsure how to call this. I have tried the following:

    public void onClick(DialogInterface dialog, int which) {
                    Uri packageURI = Uri.parse("package:com.packageName");
                    Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
                    startActivity(uninstallIntent);
    

    but the syntax is wrong. Have tried a number of different ways of calling this, and am kind of stuck. Not sure how to call this. Thanks for your help.

  • benbeel
    benbeel over 12 years
    Thanks for that. Do you know of an intent that opens the uninstall application activity?
  • Kurtis Nusbaum
    Kurtis Nusbaum over 12 years
    @goto10 Is right (I upvoted you goto10, thanks for the tip). I've edited my answer to include that information.
  • Gaurav Agarwal
    Gaurav Agarwal almost 12 years
    The link to this example is broken. I am looking in reference to this question stackoverflow.com/questions/11062780/…
  • android developer
    android developer about 10 years
    What is the difference between "android.intent.action.DELETE" and "Intent.ACTION_DELETE" ?
  • Codebeat
    Codebeat almost 9 years
    Very cool, I'm using this after disagree with EULA, app prompt to uninstall it. To cover all versions of Android i'm using this: Intent uninstallIntent = new Intent( (Build.VERSION.SDK_INT >= 14)?Intent.ACTION_UNINSTALL_PACKAGE:Intent.ACTION_DELETE, packageUri); Thanks Kurtis, you deserve a +100.
  • Mihir Trivedi
    Mihir Trivedi over 4 years
    It works if you have added permission in the manifest file <uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
  • Sumit Kumar
    Sumit Kumar over 4 years
    permission require in Android 9 and above. Otherwise uninstall dialog will not appear. Just mention in manifest file as mentioned <uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />