can I use adb shell to send commands to my application

我的未来我决定 提交于 2019-12-23 09:51:36

问题


I want to find a way to create commands that I can send to my application using the adb shell or similar. This way I can do some small changes to my program without having to reload my application every time I change anything.

Is there a way to open the adb shell and send a command to a running application ?

If that is not possible, then what is a possible way to send commands to my application so I can do things like (Move the UI Elements) or (Create a file from a URL) or a number of other things.... Essentially I want to be able to send string commands to my application.....

If I can do that with the command line tools that would be sweet. otherwise What would be a good way to go about this ?


回答1:


From an adb shell, type am. You can start activities and services as well as send broadcast intents. No arguments will print usage info.

From the host machine you can do adb shell am <command> if you want to invoke this from scripts.




回答2:


The adb shell am option is probably the cleanest/best/most awesome option, but you could have a Thread in your app checking for the presence of a specific file on the SD card. Something like (DON'T USE THIS CODE WITHOUT SERIOUS MODIFICATIONS):

public void run()
{
   File f = new File("/sdcard/appcommands");
   while(!stop){
      if(f.exists()){
         // read file
         // obey commands
         // remove file or use some other timing monitor
      }
   }
}

then you can just use adb push to write command files. Truly inefficient, but it can be made to work in a pinch. You can also do more complex things like creating local TCP/HTTP servers and using adb port forwarding, but that may just be overkill.



来源:https://stackoverflow.com/questions/5811828/can-i-use-adb-shell-to-send-commands-to-my-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!