静默安装apk
来源:互联网 发布:虚幻4引擎和unity3d 编辑:程序博客网 时间:2024/05/30 05:22
final String archiveFilePath = getInstallApkFullPath(); if (!(archiveFilePath == null)) { // 判断字符串是否为空要用==, 不要用equals方法 LogUtil.d(TAG, "run: start to install apk: " + archiveFilePath);// String[] args = {"pm", "install", "-r", archiveFilePath}; 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('*'); 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(); } } } else { LogUtil.d(TAG, "no apk need to install"); } }
private String getInstallApkFullPath() { String apkDirPath = Environment.getExternalStorageDirectory().getPath() + "/Download"; File apkFile = new File(apkDirPath); File[] apkFiles = apkFile.listFiles(); for (int i = 0; i < apkFiles.length; i++) { if (needUpdate(apkFiles[i].getAbsolutePath())) { LogUtil.d(TAG, "run: start to install apk: " + apkFiles[i].getAbsolutePath()); return apkFiles[i].getAbsolutePath(); } } return null;}
0 0
- 静默安装apk,静默卸载apk
- 静默安装APK
- android 静默安装apk
- android 静默安装Apk
- Android静默安装apk
- android静默安装apk
- android apk静默安装
- Android静默安装apk
- 静默安装apk
- android APK静默安装
- apk 静默安装
- 关于静默安装apk
- 静默安装apk
- Android 静默安装apk
- android静默安装、静默卸载apk方法
- 关于apk的 静默安装
- APK静默安装与更新
- 静默安装apk的实现
- java基础--学习总结
- 处理中文链接
- git常用操作命令
- POJ1037————A decorative fence(动态规划)
- JAVA从入门到精通(12)-- 错误处理
- 静默安装apk
- MINA、Netty、Twisted一起学(十二):HTTPS
- 数组和链表的优缺点
- 深入Java关键字this的用法和总结
- 图片裁剪控件ImageViewCrop
- Java-使用Callable实现多线程的之JDK源码简单学习实践
- KMP算法
- 5种控制变量可学习性的方法(PyTorch)
- android中ListView学习笔记