应用的安装方式:adb install或者下载安装

过程分析请參考老罗的blog,这里记录一下第三方应用程序安装apk的过程。

安装的过程主要是调用PackageInstaller这个App,源码的位置在package/app/PackageInstaller

AndroidManifest.xml例如以下,

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.packageinstaller"> <original-package android:name="com.android.packageinstaller" /> <uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
<uses-permission android:name="android.permission.CLEAR_APP_CACHE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CLEAR_APP_USER_DATA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_USERS" />
<application android:label="@string/app_name"
android:allowBackup="false"
android:theme="@android:style/Theme.DeviceDefault.DialogWhenLarge.NoActionBar">
<activity android:name=".PackageInstallerActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:excludeFromRecents="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.INSTALL_PACKAGE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:mimeType="application/vnd.android.package-archive" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.INSTALL_PACKAGE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:scheme="package" />
</intent-filter>
</activity>
<activity android:name=".InstallAppProgress"
android:configChanges="orientation|keyboardHidden|screenSize">
</activity>
<activity android:name=".UninstallerActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:excludeFromRecents="true"
android:theme="@android:style/Theme.DeviceDefault.Dialog.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.DELETE" />
<action android:name="android.intent.action.UNINSTALL_PACKAGE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
</activity>
<activity android:name=".UninstallAppProgress"
android:configChanges="orientation|keyboardHidden|screenSize">
</activity>
<!--
<receiver android:name=".RemoveReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
-->
</application>
</manifest>

安装和卸载APP主要用到了PackageInstallerActivity和UninstallActivity。

安装一个应用程序的步骤例如以下:

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);

卸载一个应用程序的步骤例如以下:

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

默认是不支持非市场安装的,这里可推断一下:

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);
}

Android PackageInstaller 安装和卸载的更多相关文章

  1. Android预安装可卸载程序

    /***************************************************************************** * Android预安装可卸载程序 * 说 ...

  2. Android ADT安装与卸载

    Android ADT安装 Eclipse 版本: Eclipse Java EE IDE for Web Developers. Version: Kepler Release Build id: ...

  3. Android中实现静态的默认安装和卸载应用

    近期好长时间都没有写blog了,主要是由于近期工作上的事以及下载Android源代码的事耽误的(下载源代码这件事会在兴许的blog中写道.这个真的非常有意义呀~~),那么今天来写点什么呢?基本的灵感来 ...

  4. android黑科技系列——实现静态的默认安装和卸载应用

    一.访问隐藏的API方式进行静态的默认安装和卸载 1.系统安装程序 android自带了一个安装程序—/system/app/PackageInstaller.apk.大多数情况下,我们手机上安装应用 ...

  5. Android随笔之——静默安装、卸载

    随笔之所以叫随笔,就是太随意了,说起来,之前的闹钟系列随笔还没写完,争取在十月结束之前找时间把它给写了吧.今天要讲的Android APK的静默安装.卸载.网上关于静默卸载的教程有很多,更有说要调用隐 ...

  6. Android监听应用程序安装和卸载

    Android监听应用程序安装和卸载 第一. 新建监听类:BootReceiver继承BroadcastReceiver package com.rongfzh.yc; import android. ...

  7. Android apk的安装、卸载、更新升级(通过Eclipse实现静默安装)

    一.通过Intent消息机制发送消息,调用系统应用进行,实现apk的安装/卸载 . (1) 调用系统的安装应用,让系统自动进行apk的安装 String fileName = "/data/ ...

  8. android程序的安装与卸载

    Android android在安装应用程序与卸载应用程序时都会发送广播,安装应用程序成功时会发送android.intent.action.PACKAGE_ADDED广播,可以通过intent.ge ...

  9. Android(java)学习笔记177:BroadcastReceiver之 应用程序安装和卸载 的广播接收者

           国内的主流网络公司(比如网易.腾讯.百度等等),他们往往采用数据挖掘技术获取用户使用信息,从而采用靶向营销.比如电脑上,我们浏览网页的时候,往往会发现网页上会出现我们之前经常浏览内容的商 ...

随机推荐

  1. [LeetCode] Unique Paths 2

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  2. Python基础 2----Python 基础语法

    1 模块导入原理 1 模块是包含函数,类,变量的独立的Python文件 2 导入系统的模块 比如我在家目录下创建一个m.py的文件,我们导入了许多的系统模块,比如time,string等等.这边就类似 ...

  3. 链栈之C++实现

    链栈是借用单链表实现的栈.其不同于顺序栈之处在于: 1.链栈的空间是程序运行期间根据需要动态分配的,机器内存是它的上限.而顺序栈则是 静态分配内存的. 2.链栈动态分配内存的特性使得它一般无需考虑栈溢 ...

  4. D2010 RTTI + Attribute 简单实现ORM

    还记得David I 今年四月来盛大时,被问及“反射机制能再做得好一点吗?我们想放弃RTTI”,David I 回答“这的确是需要考虑的地方,当然RTTI我们不会放弃的”.(这个白胡子的老哥哥还真很可 ...

  5. NetBSD是个开源到源码的系统

    How to get NetBSD NetBSD is an Open Source operating system, and as such it is freely available for ...

  6. Mybatis在oracle、mysql、db2、sql server的like模糊查询

    <!-- oracle --> <select id="searchUserBySearchName" parameterType="java.lang ...

  7. RegisterHotKey注册热键,然后响应WM_HOTKEY消息

    MSDN中的一个示例代码,步骤就是RegisterHotKey注册热键,然后响应WM_HOTKEY消息 @1:这个是系统热键 #include "stdafx.h" int _cd ...

  8. CodeForces 377B---Preparing for the Contest(二分+贪心)

    C - Preparing for the Contest Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d ...

  9. 优酷m3u8视频源地址获取失败

    昨天和今天上午,优酷站点视频全然没有办法播放,可是我是获取的优酷视频的视频原地址,所以app还是能够正常播放而且有下载功能.今天下午開始,优酷视频网页能够訪问了,可是视频原地址却不在了.我全部的app ...

  10. 2015年十大热门Android开源新项目

    2015年十大热门Android开源新项目 2015 即将结束,又到了大家喜闻乐见的年终盘点时刻啦,今天给大家盘点一下 2015 年 Android 开发领域新出现的 10 大热门开源项目.数据来自于 ...