Android 通过busybox命令行静默安装apk [英] Android Install apk silently by busybox command-line

查看:49
本文介绍了Android 通过busybox命令行静默安装apk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 BusyBox 命令在后台静默安装 .apk.我见过一些类似的问题,比如THIS,但我仍然无法工作我的代码正确...

I want to install .apk silently in background by BusyBox command. I`ve seen some similar questions like THIS, but I still cant get working my code properly...

我有:

  1. 我的 .apk 我需要安装在/sdcard/download/app.apk 上
  2. 安装了 BusyBox

代码(不工作):

String sss = Environment.getExternalStorageDirectory() + "/download/" + "app.apk";
Process install;
install = Runtime.getRuntime().exec("/system/xbin/busybox pm install " + sss); 
int success = install.waitFor();

如果我使用install"而不是pm install",它会很好地复制文件.

If I use "install" instead of "pm install" it copies file well.

附言上面的代码在 AsyncTask 中执行.没有错误,但也没有任何反应......请帮忙!

P.S. Code above is executing in AsyncTask. No errors, but also nothing happens... Please help!

我也试过这个,但我得到了退出值 139 并且没有结果:

Also I tried this, but I`m getting exit value 139 and no result:

        Process process;
        process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        os.writeBytes("pm install /mnt/sdcard/app.apk\n");
        os.flush();
        os.writeBytes("exit\n");
        os.flush();

        int i = process.waitFor();

推荐答案

经过对许多 android 设备的大量调查后,我意识到这段代码是正确且有效的!

After a lot of investigations on many android devices I realized that this code is correct and works!

一台设备(Samsung Galaxy Tab 2 7.0 - 4.0.3 ICS)出现问题.也许这是 ICS 的一些奇怪功能.更新固件至 4.1.2 (Jelly Bean) 后问题已解决.

There was just some problem with one device (Samsung Galaxy Tab 2 7.0 - 4.0.3 ICS). Maybe that is some strange feature of ICS. After updating firmware to 4.1.2 (Jelly Bean) problem has been resolved.

这篇关于Android 通过busybox命令行静默安装apk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆