【问题标题】:How to Programmatically press a button on Install/UnInstall APK Screen in android如何以编程方式在 android 的安装/卸载 APK 屏幕上按下按钮
【发布时间】:2012-11-09 10:24:21
【问题描述】:

基本上,我想从远程服务器在我的 android 设备上安装/卸载应用程序。

我从远程服务器向我的设备发送特定消息(例如安装或卸载)。

但是当设备启动该过程时,系统生成的 Intent 将启动并显示以下消息。

必须按下 OK 按钮才能继续该过程。

如何以编程方式从远程服务器按下此按钮并继续该过程?

希望您能理解我要解释的内容。

有什么建议或想法吗?

【问题讨论】:

  • 无论何时打开任何对话框,用户都必须做出响应。
  • 如果您可以发送远程消息,您是否也可以发送键事件? 'adb shell 输入 keyevent xy'
  • 这也违反了安全准则。
  • 我认为如果应用程序版本由版本号按升序标识是可能的。因此,如果版本号高于以前的版本,则可以使用 intent.ACTION_DELETE,packageURI 卸载以前的版本,使用 android.content.Intent.ACTION_VIEW, packageURI 可以安装新版本
  • 如果我的新 APK 版本高于旧版本,则会再次出现相同的对话框。那么如何从远程服务器启动 keyevent。

标签: android


【解决方案1】:

我正在寻找通过从服务器发送 SMS 来卸载任何应用程序的相同解决方案。 贝娄我提供了一些示例代码,它可能会对您有所帮助。但是您需要您的设备作为根设备。 要为您的设备生根,请从以下链接下载 s/w http://forum.xda-developers.com/showthread.php?t=803682

代码是

public class MainActivity extends Activity {

    Context context;

    // boolean isEnabled;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Uninstall();
    }

    private void Uninstall() {
        Process process;
        try {

            process = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(process.getOutputStream());
            os.writeBytes("mount -o remount,rw -t rfs /dev/stl5 /system; \n");
            os.writeBytes("rm -r /system/app/ActionsContentViewExample.apk; \n");
            os.writeBytes("mount -o remount,ro -t rfs /dev/stl5 /system; \n");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

【讨论】:

    【解决方案2】:

    恐怕这只能来自play store。点击回收站,但不要点击外部应用。

    您只能要求系统卸载应用程序。 Here's the reference.

    另外,正如 cmets 中所指出的:

    • 当您打开一个对话框时,选择是由用户驱动的。
    • 这违反了安全准则。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-12
      • 1970-01-01
      • 2019-09-07
      • 2011-09-15
      • 1970-01-01
      • 2011-06-13
      • 1970-01-01
      • 2015-01-01
      相关资源
      最近更新 更多