有自己的系统rom代码,要实现批量安装一个软件,但是安装和升级不要跳出确认框,网上找了很多资料提示要静默安装,不知道应该怎么改,改在哪
正常的系统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;}
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
有一天你能到我的心里去,你会看到那里全是你给的伤悲。
文章 0 评论 0
接受
发布评论
评论(1)
正常的系统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;
}