1. 安装程序

  1. String fileName = Environment.getExternalStorageDirectory() + "/myApp.apk";       
  2. Intent intent = new Intent(Intent.ACTION_VIEW);    
  3.    
  4. intent.setDataAndType(Uri.parse("file://" + filePath),"application/vnd.android.package-archive");    
  5. //或者    
  6. //intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");     
  7.    
  8. startActivity(intent);   

2.删除程序

  1. Uri packageURI = Uri.parse("package:com.android.myapp");       
  2. Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);       
  3. startActivity(uninstallIntent);   

默认是不支持安装非市场程序的 因此判断一下

  1. int result = Settings.Secure.getInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, 0);       
  2. if (result == 0) {       
  3. // show some dialog here       
  4. // ...       
  5. // and may be show application settings dialog manually       
  6. Intent intent = new Intent();       
  7. intent.setAction(Settings.ACTION_APPLICATION_SETTINGS);       
  8. startActivity(intent);