Can anyone say, whether adb
commands can be executed through my android application. If it is possible to execute, how it can be implemented?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
adb shell invoked in Runtime.getRuntime().exec is not running under shell user. It provide shell but with same process owner user (like u0_a44). That's the reason all command did not work.
Executing
I got the following error: java.io.IOException: Cannot run program "adb": error=13, Permission denied.
Executing
There is no error but at the same time, my request is not processed to take the screenshot.
I found out this was working in earlier versions of android but later it was removed. Though I'm not able to provide the source here why it is not working.
Hope this helps someone like me who is trying to use this approach to take the screenshot when the app is not in the foreground.
Normal Android apps have different privileges to processes started via
adb
, e.g., processes started viaadb
are allowed to the capture the screen whereas normal apps aren't. So, you can execute commands from your app viaRuntime.getRuntime().exec()
, but they won't have the same privileges as if you had executed from anadb shell
.You can do it with this:
Don't forget to surround it with a try and catch statement.
Edit:
@Phix is right, ProcessBuilder would be better to use.
i came across this post looking for a different query, but i have worked specifically with
input
on android before, so I'd just like to put some clarity on the matter.The reason why
Is not working, is because you are not removing
The
ADB
part is only for use on your computer, if you have incorrectly installed ADB, the command would actually be a path to the adb.exe file on your computer, like thisor
C:\XXXX\ADB Files\adb shell
The
shell
part tells the ADB program on your computer to access the devices shell, so your device will not know what shell is either...Using
sh /path/to/commandList.sh
will execute the commads listed in commandList.sh as it is a shell script (a .batch file on windows is similar )The command you want to use is
However this will cause Environment null and working directory null, you can bypass this by writing the commands to a shell script ( .sh file ) and then running the script with
Sometimes the
sh
is not needed, but i use it just incase.I hope this clears at least something up :)