Implicit intent to uninstall application?

前端 未结 3 1419
自闭症患者
自闭症患者 2020-12-02 11:25

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

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 12:17

    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.

提交回复
热议问题