问题
I'm wondering if Cordova or any plugin for Cordova enables me to execute a command in the android shell? Similar to doing adb shell myCoolBinary -doThisStuff on a desktop machine connected to the phone.
Googling for this only returns tutorials for how to use the Cordova cli desktop application, which absolutely NOT what I'm looking for. I want to execute commands ON the phone.
回答1:
I ended up writing my own plugin. I mostly put it together from another question that was about doing root shell executes from within your android app. I just adapted it to cordova.
I don't have the time to make this nice so here is a gist: https://gist.github.com/PTS93/d78ee885ee0c2f74892434008a953f8c
Just replace the files with the files from this plugin template: https://github.com/don/cordova-plugin-hello
You can then in your cordova app call this:
shell.execute("your shell command", success, failure);
来源:https://stackoverflow.com/questions/26875701/executing-shell-command-on-android