2024年4月19日发(作者:)

Android上的静默安装似乎是个很诱人的功能,好多人都问这个问题。今天分享下实

现静默安装的两种方法,但当看完这篇文章后,仍会让一些人失望滴。

Android把所有的Permission依据其潜在风险(属性名为protectionLevel )划分

为四个等级,即"normal "、 "dangerous "、 "signature "、 "signatureOrSystem "。

INSTALL_PACKAGES属于后两者。让我们看一下官方文档对后两类的描述吧。

"signature ": A permission that the system grants only if the requesting

application is signed with the same certificate as the application that declared the

permission. If the certificates match, the system automatically grants the

permission without notifying the user or asking for the user's explicit approval.

"signatureOrSystem ": A permission that the system grants only to

applications that are in the Android system image or that are signed with the

same certificates as those in the system image. Please avoid using this option, as

thesignature protection level should be sufficient for most needs and works

regardless of exactly where applications are installed. The "signatureOrSystem "

permission is used for certain special situations where multiple vendors have

applications built into a system image and need to share specific features explicitly

because they are being built together.

所以,这儿介绍的两种方法各自需要的苛刻条件如下:

1.内置到ROM。即APK包的安装位置是/system/app下。

2.使用APK的目标安装系统同样的签名。

好了,先不管这些苛刻的条件,下面讲下如何编写直接安装APK的代码,这儿使用

pm install 命令,而不是繁杂的未公开的l()方法。

[code]1.//This code come form :sodinoopen@

[] args = { "pm", "install", "-r", apkAbsolutePath };

result = "";

sBuilder processBuilder = new ProcessBuilder(args);

s process = null;

tream errIs = null;

tream inIs = null;

{

9. ByteArrayOutputStream baos = new ByteArrayOutputStream();

10. int read = -1;

11. process = ();