Installation of Android SDK and Python in Windows

I: Installation of the Android SDK

  1. You should be using either Windows XP (32-bit), Vista (32- or 64-bit), or Windows 7 (32- or 64-bit). Choose 32 or 64 bit depending on your OS.
  2. Install the JDK 6 (Java SE 6 Update 27), if you don't have it already (JRE alone is not sufficient). If you are not sure, just install as you will be informed during the installation process if the JDK has already been installed.
  3. Download the android-sdk_r12-windows.zip and unzip it to the C:\android folder of your PC. Please do not install using the recommended installer_r12-windows.exe.
  4. Launch the Android SDK and AVD Manager by going to the folder C:\android\android-sdk-windows\tools and execute Android. Install the SDK Platform Android 2.2. This will take some time.
  5. If you have an Android smartphone, installing the USB Driver for Windows is recommended
  6. Add the location of the SDK's tools/ and platform-tools to your PATH environment variable, to provide easy access to the tools. On Windows, right-click on My Computer, and select Properties. Under the Advanced tab, hit the Environment Variables button, and in the dialog that comes up, double-click on Path (under System Variables). Add the full path to the tools/ and platform-tools/ directories to the path.
  7. In this tutorial, you will run the Python programs in the Android Emulator. Before you can launch the emulator, you must create an Android Virtual Device (AVD). An AVD defines the system image and device settings used by the emulator. For Python, you need to also include an SD card (size 256MB typical)

IIA: Installation of Python on Android Emulator

    Note:
    1. The website for the SL4A / Python installation is code.google.com/p/android-scripting
    2. your AVD must have a SD card
    3. on your emulator goto Settings->Applications and enable Unknown sources
    4. run Hello World to check your installation

IIB: Installation of Python on Android Smartphone

    Note:
    1. Connect and power up the Bluetooth DAQ Starter Kit. Note the mac address.
    2. Bluetooth Starter Kit
    3. On your smartphone goto Settings->Applications and enable Unknown sources
    4. Point your smartphone browser to the installation links at m.smartphonedaq.com. Install SL4A and Python.
    5. Run Hello World to check Python installation
    6. Install the Test EMANT380 app to check the EMANT380 Bluetooth connectivity and download driver and examples scripts.
    7. Run Diagnostic.py to check the Python/EMANT380 installation. The Diagnostic.py will also display the version of the emant module. Note the following for the emant module:
      • It is a compiled python module (emant.pyc) and therefore will not appear on the SL4A scripts list
      • The emant modules for the smartphone and PC are different. To check
        import emant print emant.__version__
        The Android version will include the word android
    8. The Test EMANT380 app needs to have Bluetooth Enabled to run - even for scanning example scripts.

III: Installation of Python on Windows

RemoteControl controls the Android phone/emulator while running Python scripts on your computer. To do that you need to download and install

  1. Python 2.6.5 Windows Installer. This matches the Python version that SL4A/Python uses on the phone.
  2. PyBluez 0.18 for Python 2.6 Windows Installer. PyBluez is a python wrapper around system Bluetooth resources to allow Python developers to easily and quickly create Bluetooth applications. This is required by the EMANT380 Bluetooth DAQ module.

IV: RemoteControl

RemoteControl allows you to write scripts on your computer and run them on the phone/emulator. This is possible using SL4A's "server" support.

To use remote control with your USB connected Android smartphone, you first have to install the USB Driver for your Android Smartphone.

  1. Start an SL4A server from the Interpreter Manager. (From the SL4A frontpage, press Menu, then Interpreters, then Menu, then Start Server). Start a private server.
  2. Note the port displayed in the SL4A notification in the Android notification area. Let's say the private server within SL4A is listening on port 4321
  3. Start the DOS Command Prompt.
  4. Use adb to forward the network connection to the emulator
  5. Set the AP_PORT environment variable
  6. adb forward tcp:9999 tcp:4321 set AP_PORT=9999
    If multiple emulator/device instances are running, you need to specify a target instance when issuing adb commands. To so so, use the -s option in the command
    adb -s emulator-5556 forward tcp:9999 tcp:4321 set AP_PORT=9999
    To find which emulator/device instances are running, use the following adb command
    adb devices
  7. make sure you have the SL4A's android.py module in your Python path (i.e. in site-packages or the current directory). android.py is the only extra file you need; you don't need to do any sort of extensive SL4A install on your computer.
  8. Start Python and try the following code
  9. import android droid = android.Android() droid.makeToast("Hello from computer")
  10. If you intend to run your Python scripts outside of the DOS shell, you must set AP_PORT as a global environment variable. On Windows, right-click on My Computer, and select Properties. Under the Advanced tab, hit the Environment Variables button, and in the dialog that comes up, click on New System Variables. Add AP_PORT to the Variable name and 9999 to the Variable value.

    Otherwise you will see the following error when you run the Python test code.
  11. Traceback (most recent call last): File "", line 1, in droid = android.Android() File "C:\Python26\android.py", line 34, in __init__ self.conn = socket.create_connection(addr) File "C:\Python26\lib\socket.py", line 547, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): gaierror: [Errno 11001] getaddrinfo failed

For more information on RemoteControl, visit the RemoteControl webpage