2.使用pm指令安装即可。
3.特别注意 PM指令不支持中文,也就说路径中有中文会导致安装失败!
关键代码如下:
execRootCmdSilent("pm install -r " + Environment.getExternalStorageDirectory().getPath()+"/xxx.apk")不需要在Manifest中声明任何权限
- public int execRootCmdSilent(String cmd) {
- int result = -1;
- DataOutputStream dos = null;
- try {
- Process p = Runtime.getRuntime().exec("su");
- dos = new DataOutputStream(p.getOutputStream());
- Log.i(TAG, cmd);
- dos.writeBytes(cmd + "\n");
- dos.flush();
- dos.writeBytes("exit\n");
- dos.flush();
- p.waitFor();
- result = p.exitValue();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (dos != null) {
- try {
- dos.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return result;
- }
来源: http://www.phpxs.com/code/1002678/