如何在 Android Studio 源代码中 运行 adb 命令?
How to run adb command in Android Studio sourcecode?
muteButton.setOnClickListener {
Runtime.getRuntime().exec("adb shell settings put system csc_pref_camera_forced_shuttersound_key 0");
}
这是我的代码,下面是日志消息。
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:502)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.io.IOException: Cannot run program "adb": error=13, Permission denied
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050)
at java.lang.Runtime.exec(Runtime.java:698)
at java.lang.Runtime.exec(Runtime.java:528)
at java.lang.Runtime.exec(Runtime.java:425)
at pakage_name.MainActivity.onCreate$lambda-0(MainActivity.kt:16)
at pakage_name.MainActivity.$r8$lambda$ho6D_gaRxTXOpx0ACOxYNLNSY60(Unknown Source:0)
我觉得
Caused by: java.io.IOException: Cannot run program "adb": error=13, Permission denied
是一个原因。我应该如何修改我的代码?
adb
命令是一个安装在您的 PC 上的程序,它会在 android 设备中打开一个 shell。如果你使用原生代码,你不需要(也不能)使用它 - 只需删除它并直接调用命令:
Runtime.getRuntime().exec("settings put system csc_pref_camera_forced_shuttersound_key 0");
muteButton.setOnClickListener {
Runtime.getRuntime().exec("adb shell settings put system csc_pref_camera_forced_shuttersound_key 0");
}
这是我的代码,下面是日志消息。
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:502)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.io.IOException: Cannot run program "adb": error=13, Permission denied
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050)
at java.lang.Runtime.exec(Runtime.java:698)
at java.lang.Runtime.exec(Runtime.java:528)
at java.lang.Runtime.exec(Runtime.java:425)
at pakage_name.MainActivity.onCreate$lambda-0(MainActivity.kt:16)
at pakage_name.MainActivity.$r8$lambda$ho6D_gaRxTXOpx0ACOxYNLNSY60(Unknown Source:0)
我觉得
Caused by: java.io.IOException: Cannot run program "adb": error=13, Permission denied
是一个原因。我应该如何修改我的代码?
adb
命令是一个安装在您的 PC 上的程序,它会在 android 设备中打开一个 shell。如果你使用原生代码,你不需要(也不能)使用它 - 只需删除它并直接调用命令:
Runtime.getRuntime().exec("settings put system csc_pref_camera_forced_shuttersound_key 0");