Java Android Runtime.getRuntime().exec()

huangapple go评论65阅读模式
英文:

Java Android Runtime.getRuntime().exec()

问题

我正在开发一个应用程序,在其中想要使用以下方式运行 Android shell 命令:

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

这应该可以在我的应用程序上运行音乐播放器的启动/停止命令,并且当我当前在我的应用程序上时,它可以正常工作。
我执行的方式是事先在特定时间设置一个准备好的 intent,这样几分钟后我就可以播放音乐。

然而,当我将应用程序保持在后台运行时,它就无法工作了。这些 intent 会在 Logcat 中打印出我的 Log.i 消息,所以我不确定问题出在哪里。也许这是一个权限问题?

英文:

I'm working on an app where I want to run an android shell command using:

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. Perhaps it is a permission problem?

答案1

得分: 0

原来,使用这种方法,APK 必须经过签名,设备必须获得 root 权限,而且该应用必须放置在系统应用的目录中。

英文:

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.

huangapple
  • 本文由 发表于 2020年9月23日 05:09:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/64017722.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定