简体   繁体   中英

Java Android Runtime.getRuntime().exec()

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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