如何实现android软件的自动升级和安装不弹出确认框


有自己的系统rom代码,要实现批量安装一个软件,但是安装和升级不要跳出确认框,网上找了很多资料提示要静默安装,不知道应该怎么改,改在哪

Android java

就和你赖皮 8 years, 10 months ago

正常的系统apk,是通过发一个需要安装apk的意图给系统,然后由系统的另一程序解析和安装apk,这就是你所说的需要弹出的确认框了。 网上说的静默安装能实现你的需求,就是要求你换一种安装方式。 调用adb 命了直接安装行了。 前提是你能取到root 权限。

   
  String[] args = { "pm", "install", "-r", apkAbsolutePath };
  
String result = "";
ProcessBuilder processBuilder = new ProcessBuilder(args);
Process process = null;
InputStream errIs = null;
InputStream inIs = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int read = -1;
process = processBuilder.start();
errIs = process.getErrorStream();
while ((read = errIs.read()) != -1) {
baos.write(read);
}
baos.write('/n');
inIs = process.getInputStream();
while ((read = inIs.read()) != -1) {
baos.write(read);
}
byte[] data = baos.toByteArray();
result = new String(data);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (errIs != null) {
errIs.close();
}
if (inIs != null) {
inIs.close();
}
} catch (IOException e) {
e.printStackTrace();
}
if (process != null) {
process.destroy();
}
}
return result;
}

巡音ルカ. answered 8 years, 10 months ago

Your Answer