Android Remote Control Setup
Control your Android devices while running scripts on your computer!
Wonder can be done with ASE and an android device along with scripting languages like Python, Perl, JRuby, Lua, BeanShell, JavaScript, Tcl, and shell.
Would it not be wonderful to run code on your box and the same being reflected on your android devices ?
The same is achieved with help of Scripting Layer for Android's remote control.
Before one uses the script make sure that you have a GNU/Linux box with sudo privileges and an Android device with ASE installed on it.
The below is the simple setup script I wrote to make the process easier.
# License : GPLv3
# Author : hemanth.hm <[email protected]>
# Site : h3manth.com
# Purpose : Remote control android setup process
function check_sudo(){
# Check if the user has sudo privilages
sudo -v >/dev/null 2>&1 || { echo $(whoami) has no sudo privileges ; exit 1; }
}
function setup(){
# Check if the use have sudo privileges, if fine, move on.
check_sudo
# Get the latest version of android SDK.
echo -e "Download and extracting the latest version of android sdk to /opt dir\n"
(
cd /opt
curl -s $(curl -s "http://developer.android.com/sdk/index.html" | grep -o -E 'href="([^"#]+).tgz"' | cut -d'"' -f2) | tar xz && echo "Completed download of sdk" || echo "Unable to download the SDK!"
# exit has the download did not happen
exit 1
cd android-sdk-linux
echo -e "\nUpdating SDK and fetching tools..."
tools/android update sdk -o --no-ui \
--filter platform,platform-tool,tool,system-image
echo -e "\nDone updating!"
echo -e "\nAppending PATH to have android sdk tools"
echo "PATH=\"\${PATH}:~/android-sdk-linux/tools\"" >> ~/.bashrc
# Source ~/.bahrc so that the path is updated
source ~/.bashrc
# Start server
sudo ./adb kill-server && sudo ./adb start-server
echo -e "\n Almost done, now start a public/private server on your phone. Note : If private server phone must be connected via USB."
# As of now, not worrying about validating IP, cause the users who will be using this script will be sane enough to give the right IP :)
read -p "Enter IP:PORT of the server which is running on your phone" FIP
# Extract IP and PORT from the value read above.
local IP = $( echo FIP | cut -f1 -d":")
local PORT = $( echo FIP | cut -f2 -d":")
# Port forwarding
sudo ./adb forward tcp:9999 tcp:$PORT
# Export host and port
[[ ! -z $IP ]] && export AP_HOST = $IP
[[ ! -z $PORT ]] && export AP_PORT = $PORT
# Get the site_package location
site_package_path = $(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
# Get SLA4's android.py
echo -e "\n Getting SLA4's android.py to $site_package_path"
curl -s "http://android-scripting.googlecode.com/hg/python/ase/android.py" > $site_package_path/android.py
)
}
echo -e "Starting the setup...\n"
setup
echo -e "Done with the setup! import android and explore!"
To setup your machine just do the below :
Now you can control your Android device from your terminal, using ASE API
For example, the below code would sent a toast to your Android device from your terminal :
$ python Python 2.6 Type "help", "copyright", "credits" or "license" for more information. >>> import android # The SL4A android.py module should be on your sys.path. >>> droid = android.Android() # Or android.Android(('Public IP', PORT)) >>> droid.makeToast("Hello from my GNU!")
< /br>
FORK it from https://github.com/hemanth/android-remote-control-setup
Enjoy the power of free and open software!
Recent blog posts
- watir-webdriver web inspector
- gem list to gemfile
- Packing ruby2.0 on debian.
- Made it into The Guinness Book!
- to_h in ruby 2.0
- Filter elements by pattern jQuery.
- Better HTML password fields for mobile ?
- Grayscale image when user offline
- nth-child CSS pseudo-class Christmas colors
- EventEmitter in nodejs