Showing posts with label Uninstall Android App Programmatically. Show all posts
Showing posts with label Uninstall Android App Programmatically. Show all posts

Tuesday, February 14, 2012

Uninstall App programmatically in Android


Today we will learn How to an Android Application can Uninstall itself Programmatically


Note:  here we need to pass package name in URI
so we are passing package name in which main/default/startup Activity Present
that we also define in manifest file at top level

Okay let's try this simple app

 -------------------------------------------
App Name: UninstallApp
Package Name: com.rdc
Android SDK: Android SDK 2.3.3 / API 10
Default Activity Name: UninstallAppActivity
-------------------------------------------


UninstallAppActivity.java


package com.rdc;

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

public class UninstallAppActivity extends Activity {
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  Button btn = (Button) findViewById(R.id.button1);
  btn.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    Uri packageUri = Uri.parse("package:com.rdc");
    Intent uninstallIntent = new Intent(Intent.ACTION_DELETE,
      packageUri);
    startActivity(uninstallIntent);
   }
  });
 }
}

main.xml

 


AndroidManifest.xml

 

 
  
   
    
    
   
  

 


The output Screen will be like this..


You can download the complete source code zip file here : UninstallApp

 cheers!!

 I'd love to hear your thoughts!