【问题标题】:Execute adb shell commands inside my android application [duplicate]在我的android应用程序中执行adb shell命令[重复]
【发布时间】:2017-08-29 02:54:42
【问题描述】:

我需要在我的设备启动时应用某些 adb 命令。但是假设我在启动应用程序时需要它。

adb shell settings put global policy_control immersive.navigation=*

我在网上搜索并想出了

Process p = Runtime.getRuntime().exec("settings put global policy_control immersive.navigation=*");

但不幸的是,这个命令不起作用。如果我将手机插入 PC 并直接通过命令窗口运行 adb 命令 - 一切都很好。但是当我从应用程序执行它时 - 没有任何效果,我什至没有在日志中看到任何相关的错误。

我也试过这个: https://www.learn2crack.com/2014/03/android-executing-shell-commands.html 像“ls /system/framework”这样的命令可以工作。但我需要的 - 不需要。

我的设备是运行基于 android 6.0.1 的 miui 8 的 redmi note 3 pro。我的项目在 Eclipse 中。

是否可以在没有root的情况下执行这样的任务?

【问题讨论】:

    标签: java android shell adb


    【解决方案1】:

    代替:

    Process p = Runtime.getRuntime().exec("settings put global policy_control immersive.navigation=*");
    

    尝试:

    Process p = Runtime.getRuntime().exec(new String[]{"settings", "put", "global", "policy_control", "immersive.navigation=*");
    

    exec 期望命令是一个字符串数组,其中第一个字符串是命令,其余的是它的参数

    【讨论】:

    • command.split(" ")
    猜你喜欢
    • 1970-01-01
    • 2011-02-06
    • 1970-01-01
    • 1970-01-01
    • 2015-05-01
    • 2014-03-12
    • 2013-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多