packageinstaller实验静默安装与卸载的关键代码
来源:互联网 发布:java 获取pom 版本号 编辑:程序博客网 时间:2024/05/13 20:46
String[] args = { "pm", "install", "-r", fileName };
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();
}
}
Log.e("kkk","result------->"+result);
return result;
}
private String unInstallApk(String packageName) {
String[] args = { "pm", "uninstall", packageName };
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;
}
- packageinstaller实验静默安装与卸载的关键代码
- PackageInstaller 5.0源码分析静默安装与静默卸载
- 代码流程分析三:PackageInstaller-安装与卸载应用程序
- Android PackageInstaller 静默安装的实现
- innosetup的静默安装与卸载
- Android PackageInstaller 静默安装的实现(附源码)
- WINDOWS 下静默安装 与 静默卸载
- android静默安装与静默卸载
- Android PackageInstaller 安装和卸载
- Android实现静默安装与卸载
- Android实现静默安装与卸载
- Android实现静默安装与卸载
- Android实现静默安装与卸载
- Android 静默安装与卸载分析
- 静默安装和静默卸载
- 积跬步至千里系列之六--安装与卸载应用程序(PackageInstaller)(一)
- 代码中执行apk安装、卸载、更新以及静默安装
- 代码中执行apk安装、卸载、更新以及静默安装
- libzbar源码
- Exercises 4.1 E2
- open-iscsi docs
- 我的读博经历回顾与经验分享
- IOS设计模式之我见-单例模式
- packageinstaller实验静默安装与卸载的关键代码
- 习题
- 用最精炼语言介绍OpenStack网络代码演进的前世今生
- startOSW.sh: ./OSWatcher.sh: /bin/ksh: bad interpreter: Permission denied
- greenplum分区表查看所占空间大小
- SSAS(分析服务)优化手册
- mp4 文件数据分析
- 谁在用Hadoop
- 通过ApplicationContextAware加载Spring上下文环境