---
title: "Android 在程序中删除程序包"
author: "wangxinasy"
date: "2010-11-29T18:01:10Z"
tags: ["Android", "Git"]
categories: ["移动开发"]
slug: "android"
draft: false
lastmod: "2010-11-29T18:01:10Z"
id: 828514
url: "https://wangxinasy.iteye.com/blog/828514"
---

Install and Uninstall Android applications with PackageInstaller This is actually very simple. See PackageInstaller code here:http://android.git.kernel.org/?p=platform/packages/apps/PackageInstaller.git;a=tree;h=refs/heads/donut;hb=refs/heads/donut Intent filters for such actions are: so if you want to install your .apk file from SD card – just write something like that: String fileName = Environment.getExternalStorageDirectory() + "/myApp.apk"; Intent intent = new Intent(Intent.ACTION\_VIEW); intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive"); startActivity(intent); for uninstallation: Uri packageURI = Uri.parse("package:com.android.myapp"); Intent uninstallIntent = new Intent(Intent.ACTION\_DELETE, packageURI); startActivity(uninstallIntent); be aware that by default INSTALL\_NON\_MARKET\_APPS option is disabled. You may want to check this option and show user friendly dialog before trying to install the app: int result = Settings.Secure.getInt(getContentResolver(), Settings.Secure.INSTALL\_NON\_MARKET\_APPS, 0); if (result == 0) { // show some dialog here // ... // and may be show application settings dialog manually Intent intent = new Intent(); intent.setAction(Settings.ACTION\_APPLICATION\_SETTINGS); startActivity(intent); } enjoy