You are previewing Pro Android Python with SL4A.
O'Reilly logo
Pro Android Python with SL4A

Book Description

Pro Android Scripting with SL4A is for programmers and hobbyists who want to write apps for Android devices without having to learn Java first. Paul Ferrill leads you from installing the Android Scripting Layer, to writing small scripts, to more complicated and interesting projects, and finally to uploading and packaging your programs to an Android device.

Android runs scripts in many scripting languages, but Python, Lua, and Beanshell are particularly popular. Most programmers know more than one programming language, so that they have the best tool for whatever task they want to accomplish. Pro Android Scripting with SL4A explores the world of Android scripting by introducing you to the most important open source programming languages that are available on Android-based hardware.

Pro Android Scripting with SL4A starts by exploring the Android software development kit and then shows you how to set up an Eclipse-based Android development environment. You then approach the world of Android programming by using Beanshell, which runs on the Dalvik, and learn how to write small programs to administer an Android device.

You will then discover how Lua, a lightweight language perfectly suited for scripting on smaller devices, can work with Android. Lua can be used for small but important tasks, like SMS encryption and synchronizing photos with flickr.

Last, but certainly not least, you will discover the world of Python scripting for SL4A, and how powerful this Android scripting option can be, with the full range of Python modules that can combine with the Android SDK. You'll learn to write small location-aware apps to get you started, but by the end of this book you'll find yourself writing fully GUI-fied applications running on the Android Desktop!

Pro Android Scripting with SL4A is rounded out with a chapter on distributing and packaging scripts, a skill that you'll find is very useful as you reach out to a wider audience with your programs.

What you'll learn

  • Understand the SL4A layer

  • Explore the Android software development kit

  • Write scripts to administer an Android phone

  • Write and execute full Python and applications

  • Learn how to write simple apps using Facades

  • Explore the full Android development process from development to packaging

Who this book is for

This is a book for beginning and intermediate Android developers, and a book for anyone coding in Python, Lua or exploring Beanshell.

Table of Contents

  1. Copyright
  2. About the Author
  3. About the Technical Reviewer
  4. Acknowledgments
  5. Preface
  6. 1. Introduction
    1. 1.1. Why SL4A?
    2. 1.2. The World of Android
    3. 1.3. Android Application Anatomy
    4. 1.4. Activities
    5. 1.5. Intents
    6. 1.6. SL4A History
    7. 1.7. SL4A Architecture
    8. 1.8. SL4A Concepts
    9. 1.9. JavaScript Object Notation (JSON)
    10. 1.10. Events
    11. 1.11. Languages
      1. 1.11.1. Beanshell 2.0b4
      2. 1.11.2. Lua 5.1.4
      3. 1.11.3. Perl 5.10.1
      4. 1.11.4. PHP 5.3.3
      5. 1.11.5. Rhino 1.7R2
      6. 1.11.6. JRuby 1.4
      7. 1.11.7. Shell
      8. 1.11.8. Python
        1. 1.11.8.1. Language Basics
          1. 1.11.8.1.1. Dictionary: An Unordered Set of Key/Value Pairs Requiring Unique Keys
          2. 1.11.8.1.2. List: A Built-In Python Sequence Similar to an Array in Other Languages
          3. 1.11.8.1.3. String: An Immutable Sequence Made Up of Either ASCII or Unicode Characters
          4. 1.11.8.1.4. Tuple: An Immutable List
        2. 1.11.8.2. Python Standard Library
    12. 1.12. Summary
  7. 2. Getting Started
    1. 2.1. Installing SL4A on the Device
    2. 2.2. Installing the Android SDK
      1. 2.2.1. Linux
      2. 2.2.2. Mac OS X
      3. 2.2.3. Windows
    3. 2.3. Installing Python
    4. 2.4. Remotely Connecting to the Device
      1. 2.4.1. Device Settings
    5. 2.5. Executing Simple Programs
    6. 2.6. Summary
  8. 3. Navigating the Android SDK
    1. 3.1. Wading Through the SDK Documentation
    2. 3.2. Examining the Different SDK Components
    3. 3.3. Testing With the Android Emulator
      1. 3.3.1. Android Debug Bridge
        1. 3.3.1.1. Files and Applications
        2. 3.3.1.2. The Shell
        3. 3.3.1.3. logcat
      2. 3.3.2. Dalvik Debug Monitor Service (DDMS)
    4. 3.4. Summary
  9. 4. Developing with Eclipse
    1. 4.1. Installing Eclipse on a Development Machine
    2. 4.2. Eclipse Basics
      1. 4.2.1. Perspectives
      2. 4.2.2. Projects
    3. 4.3. Android Development Toolkit
    4. 4.4. Using Pydev
      1. 4.4.1. Using Multiple File Types in Eclipse
    5. 4.5. Summary
  10. 5. Exploring the Android API
    1. 5.1. Exploring the Android APIs
    2. 5.2. Android Facades
      1. 5.2.1. ActivityResultFacade
      2. 5.2.2. AndroidFacade
      3. 5.2.3. ApplicationManagerFacade
      4. 5.2.4. BatteryManagerFacade
      5. 5.2.5. BluetoothFacade
      6. 5.2.6. CameraFacade
      7. 5.2.7. CommonIntentsFacade
      8. 5.2.8. ContactsFacade
      9. 5.2.9. EventFacade
      10. 5.2.10. EyesFreeFacade
      11. 5.2.11. LocationFacade
      12. 5.2.12. MediaPlayerFacade
      13. 5.2.13. MediaRecorderFacade
      14. 5.2.14. PhoneFacade
      15. 5.2.15. PreferencesFacade
      16. 5.2.16. SensorManagerFacade
      17. 5.2.17. SettingsFacade
      18. 5.2.18. SignalStrengthFacade
      19. 5.2.19. SmsFacade
      20. 5.2.20. SpeechRecognitionFacade
      21. 5.2.21. TextToSpeechFacade
      22. 5.2.22. ToneGeneratorFacade
      23. 5.2.23. UiFacade
      24. 5.2.24. WakeLockFacade
      25. 5.2.25. WebCamFacade
      26. 5.2.26. WifiFacade
    3. 5.3. Summary
  11. 6. Background Scripting with Python
    1. 6.1. Background Tasks
    2. 6.2. Triggers
    3. 6.3. Orientation-based Actions
    4. 6.4. Location-based Actions
    5. 6.5. Time-based Actions
    6. 6.6. Elapsed Time-based Triggers
    7. 6.7. FTP File Sync Tool
    8. 6.8. Syncing Photos with Flickr
    9. 6.9. Syncing with Google Docs
    10. 6.10. A Startup Launcher
    11. 6.11. Summary
  12. 7. Python Scripting Utilities
    1. 7.1. Python Libraries
    2. 7.2. E-mail–Based Applications
    3. 7.3. Location-Aware Applications
      1. 7.3.1. Tweet My Location
        1. 7.3.1.1. Track My Travel
        2. 7.3.1.2. WiFi Scanner
        3. 7.3.1.3. HTTP Server
      2. 7.3.2. Killing a Running App
    4. 7.4. URL File Retriever
    5. 7.5. Python FTP Server
    6. 7.6. Summary
  13. 8. Python Dialog Box–based GUIs
    1. 8.1. UI Basics
    2. 8.2. Book Title Search
      1. 8.2.1. Convenience Dialog Boxes
      2. 8.2.2. Progress Dialog Boxes
      3. 8.2.3. Modal versus Non–Modal Dialog Boxes
      4. 8.2.4. Options Menu
      5. 8.2.5. File Listing with dialogCreateAlert
      6. 8.2.6. Dialog Boxes as Python Objects
      7. 8.2.7. Podplayer App
      8. 8.2.8. Building the mysettings App
    3. 8.3. Summary
  14. 9. Python GUIs with HTML
    1. 9.1. HTML and Basic Information Display
    2. 9.2. HTML and JavaScript
    3. 9.3. HTML GUI Form Basics
      1. 9.3.1. Simple HTML Forms
      2. 9.3.2. Cascading Style Sheets
      3. 9.3.3. SMS Merger
        1. 9.3.3.1. Dependencies
        2. 9.3.3.2. Quirks and Gotchas with SMS Sender
    4. 9.4. Summary
  15. 10. Packaging and Distributing
    1. 10.1. QR Codes
    2. 10.2. Application Packages
    3. 10.3. Packaging Your Own Application
    4. 10.4. Building with Ant
    5. 10.5. Compiling SL4A
    6. 10.6. Finishing Touches
    7. 10.7. Winding Down
    8. 10.8. Summary