Android 静默安装实现方法
作者:lqh 时间:2021-08-04 05:11:25
Android静默安装的方法,静默安装就是绕过安装程序时的提示窗口,直接在后台安装。
注意:静默安装的前提是设备有ROOT权限。
代码如下:
/**
* 静默安装
* @param file
* @return
*/
public boolean slientInstall(File file) {
boolean result = false;
Process process = null;
OutputStream out = null;
try {
process = Runtime.getRuntime().exec("su");
out = process.getOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(out);
dataOutputStream.writeBytes("chmod 777 " + file.getPath() + "\n");
dataOutputStream.writeBytes("LD_LIBRARY_PATH=/vendor/lib:/system/lib pm install -r " +
file.getPath());
// 提交命令
dataOutputStream.flush();
// 关闭流操作
dataOutputStream.close();
out.close();
int value = process.waitFor();
// 代表成功
if (value == 0) {
result = true;
} else if (value == 1) { // 失败
result = false;
} else { // 未知情况
result = false;
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return result;
}
注意代码中pm install -r 前面的LD_LIBRARY_PATH=/vendor/lib:/system/lib,在4.0版本以上必须加上,不然会无法安装。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
来源:http://blog.csdn.net/paulluo0739/article/details/8833397
标签:Android,静默安装
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
windows下java环境变量的设置方法
2022-12-01 03:13:14
SpringBoot面试突击之过滤器和拦截器区别详解
2022-10-13 02:02:05
![](https://img.aspxhome.com/file/2023/8/84638_0s.png)
解决Java API不能远程访问HBase的问题
2023-11-27 04:17:48
![](https://img.aspxhome.com/file/2023/2/86852_0s.png)
C#先判断是否存在再创建文件夹或文件与递归计算文件夹大小
2023-07-29 00:04:58
![](https://img.aspxhome.com/file/2023/6/89806_0s.png)
详细解读JAVA多线程实现的三种方式
2022-01-14 04:35:31
Java虚拟机之类加载
2022-11-15 05:19:19
![](https://img.aspxhome.com/file/2023/4/64754_0s.png)
idea创建SpringBoot项目时Type选maven project和maven pom有何区别
2023-07-04 07:20:27
![](https://img.aspxhome.com/file/2023/9/57499_0s.png)
Spring实战之清除缓存操作示例
2023-05-31 07:46:26
java求余的技巧汇总
2023-08-06 06:33:16
![](https://img.aspxhome.com/file/2023/8/57898_0s.jpg)
java两种单例模式用法分析
2023-10-06 03:51:34
一篇文章告诉你JAVA Mybatis框架的核心原理到底有多重要
2023-11-13 06:20:10
![](https://img.aspxhome.com/file/2023/5/59705_0s.png)
spring security在分布式项目下的配置方法(案例详解)
2022-12-26 03:45:49
IDEA + Maven环境下的SSM框架整合及搭建过程
2023-08-26 02:06:55
![](https://img.aspxhome.com/file/2023/3/58423_0s.jpg)
C#动态编译并执行字符串样例
2022-02-10 22:26:53
unity通过Mesh网格绘制图形球体
2023-12-12 08:08:21
![](https://img.aspxhome.com/file/2023/3/82233_0s.jpg)
springSecurity之AuthenticationProvider用法解析
2022-09-07 20:55:01
![](https://img.aspxhome.com/file/2023/9/64429_0s.png)
Java Swing中的JButton、JComboBox、JList和JColorChooser组件使用案例
2023-07-11 17:32:06
![](https://img.aspxhome.com/file/2023/1/77051_0s.jpg)
java Stream流常见操作方法(反射,类加载器,类加载,反射)
2022-03-24 06:54:56
spring boot 实现配置多个DispatcherServlet最简单方式
2023-12-18 03:24:46
![](https://img.aspxhome.com/file/2023/9/63769_0s.jpg)
Java实现的求解经典罗马数字和阿拉伯数字相互转换问题示例
2023-10-15 23:17:36
![](https://img.aspxhome.com/file/2023/9/64789_0s.png)