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; 这段代码要放在哪里执行????上面的代码来自:http://blog.csdn.net/sodino/article/details/6238818
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; 这段代码要放在哪里执行????上面的代码来自:http://blog.csdn.net/sodino/article/details/6238818
解决方案 »
- 照着这个帖子做了个sqlit的例子,出错了。。。
- web_app不同分辨率下均缩放到铺满屏幕
- android中如何实现搜索框布局
- AlarmClock的问题,求高手帮忙
- 为什么图片加载到程序中变小了?
- 关于控件移动translateAnimation问题
- 求android高手,解决不同进程间的数据共享问题
- imsdroid
- 哎呀!奇怪问题,看看我发帖的时间吧。edittext关闭软键盘
- 请问 Unhandled Exception: java.io.IOException 这种问题一般是怎么造成的?如何解决?
- 有一行有两个组件EditText和Button,Button靠最右,EditText宽度从最左到Button的左边,这个用相对布局,要怎么实现?
- Sax解析的一个问题
这两种方法都可以实现,但都不能实现通用性 1.内置到ROM。即APK包的安装位置是/system/app下。
这方法需要手机root,没有root手机行不通2.使用APK的目标安装系统同样的签名。
这方法需要目标系统相同的签名,系统不同签名不同 ,不通用要真正实现静默安装,还是得直接使用底层未提供的接口,eclipse不能编译,但源码中
mmm命令能编译生成apk,可以完美实现静默安装。