因为做的项目是装在固定设备上的,所有设备都已root
一:当前版本号与服务器版本对比 如有更新则去服务器下载新版本
这个网上很多教程不多说
二:下载完保存到某目录下,自动安装,无需手动点击确认
实现实际使用的是su pm install -r filepath命令。
核心代码如下:
protected void excutesucmd(String currenttempfilepath) {
Process process = null;
OutputStream out = null;
InputStream in = null;
try {
// 请求root
process = Runtime.getRuntime().exec("su");
out = process.getOutputStream();
// 调用安装
out.write(("pm install -r " + currenttempfilepath + "\n").getBytes());
in = process.getInputStream();
int len = 0;
byte[] bs = new byte[256];
while (-1 != (len = in.read(bs))) {
String state = new String(bs, 0, len);
if (state.equals("success\n")) {
//安装成功后的操作