Android APK的安装
打开packages\apps\PackageInstaller下的清单文件
<?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" />
<application android:label="@string/app_name">
<activity android:name=".PackageInstallerActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="@style/TallTitleBarTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="content" />
<data android:scheme="file" />
<data android:mimeType="application/vnd.android.package-archive" />
</intent-filter>
</activity>
<activity android:name=".InstallAppProgress"
android:configChanges="orientation|keyboardHidden"
android:theme="@style/TallTitleBarTheme">
</activity>
<activity android:name=".UninstallerActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="@style/TallTitleBarTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DELETE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
</activity>
<activity android:name=".UninstallAppProgress"
android:configChanges="orientation|keyboardHidden"
android:theme="@style/TallTitleBarTheme">
</activity>
</application>
</manifest>
项目布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" > <EditText
android:id="@+id/et_path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="请输入apk的路径" />
<Button
android:onClick="click"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="安装" /> </LinearLayout>
逻辑代码如下:
public class MainActivity extends Activity { private EditText et_path; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); et_path = (EditText) findViewById(R.id.et_path);
} public void click(View view) {
String path = et_path.getText().toString().trim();
/*
* <action android:name="android.intent.action.VIEW" /> <category
* android:name="android.intent.category.DEFAULT" /> <data
* android:scheme="content" /> <data android:scheme="file" /> <data
* android:mimeType="application/vnd.android.package-archive" />
*/
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.setDataAndType(Uri.fromFile(new File(path)), "application/vnd.android.package-archive");
startActivity(intent);
}
}
首先需要AndroidManifest.xml中加入安装程序权限:
<!-- 安装程序权限 -->
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
接着将一个名为girl.apk的apk导入sdcard,然后运行项目效果如下
点击安装
Android APK的安装的更多相关文章
- android apk静默安装
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/47803149 之前有很多朋友都问过我,在Android系统中怎样才能实现静默安装呢 ...
- android APK应用安装过程以及默认安装路径[转]
一:安装过程 APK是类似Symbian Sis或Sisx的文件格式.通过将APK文件直接传到Android模拟器或Android手机中执行即可安装. Android应用安装有如下四种方式 1. ...
- Android apk 的安装过程
Android应用安装有如下四种方式 1.系统应用安装――开机时完成,没有安装界面 2.网络下载应用安装――通过market应用完成,没有安装界面 3.ADB工具安装――没有安装界面. 4.第三方应用 ...
- Android apk的安装、卸载、更新升级(通过Eclipse实现静默安装)
一.通过Intent消息机制发送消息,调用系统应用进行,实现apk的安装/卸载 . (1) 调用系统的安装应用,让系统自动进行apk的安装 String fileName = "/data/ ...
- 【Android】Android apk默认安装位置设置
在Android工程中,设置apk的默认安装位置 在AndroidManifest.xml文件Manifest标签中添加android:installLocation属性 android:instal ...
- Android APK安装过程学习笔记
1.什么是APK APK,即Android Package,Android安装包.不同平台的安装文件格式都不同,类似于Windows的安装包是二进制的exe格式,Mac的安装包是dmg格式.APK可以 ...
- Python Python实现批量安装android apk包
基于Python实现批量安装android apk包 by:授客 QQ:1033553122 1.相关软件包及文件下载 下载地址:adb软件包及批量安装apk包的py文件.zip 2.测试环境 Win ...
- Android为TV端助力 apk静默安装
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/47803149 之前有很多朋友都问过我,在Android系统中怎样才能实现静默安装呢 ...
- 【树莓派】在树莓派的Android系统中安装APK应用
树莓派3 Android TV安装APK应用教程 本文摘自:http://www.mz6.net/news/android/6867.html 树莓派3 Android TV怎样安装软件?对于熟悉AD ...
随机推荐
- C#--静态函数成员
- CSS 居中方法集锦
记录收集纯CSS层面实现的水平.垂直居中方法可用于块级.行内快.内联元素以及文字图片等. 水平或垂直居中 1.1 text-align 1.2 margin 1.3 line-height 1.4 p ...
- STM32L系列单片机内部EEPROM的读写
STM32L系列单片机内部提供了EEPROM存储区域,但实质上,其FLASH也是EEPROM类型,只不过有一块区域被开放出来专门用作EEPROM操作而已.STM32L的EEPROM使用寿命设计为100 ...
- jquery的ready事件的实现机制浅析
页面初始化中,用的较多的就是$(document).ready(function(){//代码}); 或 $(window).load(function(){//代码}); 他们的区别就是,ready ...
- winform自定义日期控件,要求可以手动输入日期DatePicker
要求:文本框中能手动输入数字,向上箭头根据鼠标位置给年月日递增,向下箭头递减 一:页面加载时: private void FlatDatePicker_Load(object sender, Even ...
- GCC、ARM-LINUX-GCC、ARM-ELF-GCC浅析
一.GCC简介: The GNU Compiler Collection,通常简称GCC,是一套由GNU开发的编译器集,为什么是编辑器集而不是编译器呢?那是因为它不仅支持C语言编译,还支持C++, A ...
- 为什么要用 Bootstrap
[Bootstrap](http://hovertree.com/menu/bootstrap/) 是由两个 twitter 员工开发并开源的前端框架,非常火爆,而如此火爆自然有它的道理,在我们团队的 ...
- iOS阶段学习第21天笔记(ARC内存管理-Copy-代理)
iOS学习(OC语言)知识点整理 一.OC 中的ARC内存管理 1)ARC中释放对象的内存原则:看这个对象有没有强引用指向它 2)strong:强引用,默认情况下的引用都是强引用 3) weak:弱引 ...
- App单个页面的最佳文本框个数是多少个?
[1].不同大小的手机屏幕,对应的App每页最佳文本框个数,是不同的. [1.1]如果是iPhone4的屏幕尺寸,分辨率为640x960px的时候, 文本框个数最大值为:2个文本框 [计算公式] 第 ...
- jquery练习
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...