Nov 11, 2013

How to control Android device over USB connection

The following article describes my actions related to my particular environment and the particular set which is working for me. No warranty or respectability for any damage or side effect is taken.
However, I will do my best to answer questions posted on the blog in order to help other to configure the same.
The article assumes one has the phone drivers and  adb  already installed.


Since I use to spend countless hours in front of my PC and since most of the time a have my Android mobile connected to the USB charger, I considered some options to control the phone via browser.

Wouldn't it be convenient to read or write SMS from your PC, using a full size keyboard? Wouldn't it be great to access contacts, or systems settings trough the browser? Oh boy, I know I'd loved that!

Looking to the Market (to be noted I prefer the old Android Market naming in stead of new Play) I found a few nice Apps. like AirDroid, Remote Desktop, 3CX DroidDesktop etc. Out of all, the later - 3CX DroidDesktop, previously known as LazyDroid - is the only one which runs over an USB connections, so the one tho choose.

So far so good, until I realized there are a lot of options to perform prior to benefiting out of this marvelous set up: one needs to first connect the Android device to the computer using the USB cable, run the connection.bat script, start a browser and point it to the local address using the right port. To much for my taste... no wonder I preferred the App. known as LazyDroid.

So I started to look for ways to automate things.

Plug In Launcher. It gives you the possibility to run an application when connecting an usb cable, headsets etc...and it does it for free! :)
So I have downloaded and installed Plug in launcher on my phone and configured it to run 3CX DroidDesktop whenever it detects an USB cable connection towards a PC.

Using the instructions provided on the following link http://www.mobiledevicemanager.com/3cxdroiddesktop/manual/usb-screenshots-windows/, I have developed the following script:

@ECHO OFF
ECHO Running the connect.bat script content from C:\Program Files (x86)\Android\adb_win
:begin
set Pathname="C:\Program Files (x86)\Android\android-sdk\platform-tools"
cd /d %Pathname%
adb forward tcp:8999 tcp:8999
adb forward tcp:5901 tcp:5901
adb forward tcp:2221 tcp:2221
adb forward tcp:21000 tcp:21000
echo Now shoud be lounching http://localhost:%port%/ in browser
start chrome "http://localhost:8999/"


The script uses adb commands and part of the script connect.bat in order to configure the port forwarding. For simplicity I have decided to use the default port 8999.
Not to forger, one has to enable USB debugging in order this to work.


Further on, I needed to find a way to run the above script (called AndroRemote.bat) automatically on my PC when connecting the Android phone, the same way as I did above with the Plug In Launcher. Think is that I wouldn't like to use any additional application, but use the embedded Task Scheduler in stead.

To do that, I had to find out an event related to connecting the mobile phone to the PC's USB port. I have managed to find it in the Event Viewer, under Applications and Servvices >> Microsoft >> Windows >> DriverFrameWorks - User Mode >> Operational.


The event number in my case is 2101, as can be seen in the picture below. Further on, right click on the event would allow the possibility to attached it to the Task Scheduler and trigger an action.


The next images will illustrate how I have configured the Task Scheduler.





No comments:

Post a Comment