简体   繁体   English

Java Android Runtime.getRuntime().exec()

[英]Java Android Runtime.getRuntime().exec()

I'm working on an app where I want to run an android shell command using:我正在开发一个应用程序,我想使用以下命令运行 android shell 命令:

Process process = Runtime.getRuntime().exec("input keyevent 85");

This should start/stop the music player for me, and it works when I'm currently on my app.这应该为我启动/停止音乐播放器,并且当我当前在我的应用程序上时它可以工作。 The way I do it is to set a prepared intent beforehand at a certain time, so I can have the music playing in a few minutes.我的做法是在某个时间预先设定一个准备好的意图,这样我就可以在几分钟内播放音乐。

However, it doesn't work when I have the app running in the background.但是,当我在后台运行该应用程序时,它不起作用。 The intents do print out my Log.i messages in Logcat, so I'm not sure where the problem lies.意图确实在 Logcat 中打印出我的 Log.i 消息,所以我不确定问题出在哪里。 Perhaps it is a permission problem?也许这是一个权限问题?

Turns out, using this method, the APK would have to be signed, the device rooted and the APP be placed in the directory of system apps.事实证明,使用这种方法,必须对 APK 进行签名,对设备进行 Root,并将 APP 放置在系统应用程序的目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM