SlideShare a Scribd company logo
ANDROID SCRIPTING
 A Java-less approach to building apps

              Juan Gomez
          Android Dev @ Handmark, Inc
             Co-founder PythonKC
AGENDA

•   Android 101
•   Scripting Layer for Android (SL4A)
•   Basic tasks (WiFi, GPS, camera, SMS) and basic UI
•   Using WebViews and Javascript for better UIs
•   Advanced Scripts (Twisted, PyBluez)
•   Packaging your scripts on an APK
•   Q&A
ANDROID 101
An Android application is actually a collection of several
components, each defined in a file called AndroidManifest.xml

The 4 main types of components are:

  • Activities
  • Services
  • Content      Providers
  • Broadcast     Receivers
Apps are packaged on an APK file (myApp.apk)
INTENTS
•   Apps can communicate with each other by providing and consuming each
    other’s Intents
•   Intents “link” activities, services, and
    receivers together
•   Intents consists of
    •   An action (i.e. ACTION_VIEW)
    •   Categories (i.e. CATEGORY_DEFAULT)
    •   A URI (i.e. content://contacts/people/123)
    •   “Extras” metadata
•   Intents can also be sent to hard-coded class names (com.foo.FooActivity)
HOW DO I GET STARTED?

• Download       the Android SDK: http://developer.android.com/sdk

• Add Android      platforms and other packages to your SDK

• Install   the ADT plug-in for Eclipse (optional)

• Enable     app side-loading on your phone:

  •   Settings > Application > Unknown Sources
WHERE CAN I LEARN MORE?
• Android’s Dev Guide
  http://developer.android.com/guide
• Lots   of Android Books
• StackOverflow
• Recommended          resource:
  •   http://commonsware.com/
  •   The Busy Coder’s Guide to Android
      Development
  •   Yearly subscription
SCRIPTING LAYER FOR
              ANDROID (SL4A)
• Brings    scripting languages to Android
• Allows you to edit and execute scripts and interactive
 interpreters directly on the Android device.
• Scripts
       have access to many of the APIs available to full-
 fledged Android apps.
• Supported  languages include: Python, Perl, JRuby, Lua, BeanShell,
 JavaScript and Tcl
• There’s    limited support for PHP and Shell scripts
SL4A ARCHITECTURE
•   As it name implies, SL4A sits
    between the actual Android JVM
    (Dalvik) and the executable
    Scripts.
•   The Facade API exposes a subset
    of Android system API's via JSON
    RPC calls
•   Only the parts of Android's APIs
    which has been wrapped by
    facades are available to
    interpreter
•   This is a fundamental feature of
    SL4A added by Google to avoid
    security concerns.
WHAT CAN SL4A DO?
• Handle    intents
• Start   activities
• Make    phone calls
• Send    text messages
• Scan    bar codes
• Poll   location and sensor data
• Use    text-to-speech
HOW TO DOWNLOAD?




• Go   to: http://code.google.com/p/android-scripting/
HOW TO USE
   IT?
   SL4A installs as an App on
    your phone, you need to
  install separate interpreters
for each language you want to
               use
INTERPRETERS
 Open up the App, click on
Menu > View > Interpreters to
  get a list of the available
         interpreters
DOWNLOAD
Click on Menu > Add to get a
 list of new interpreters you
   can install on your phone
INSTALL
 Click on an Interpreter from
the list and this will download
  an .APK with the installer.
SCRIPTS
 When you open the SL4A
  app you get a list of your
available scripts. You can use a
  quick action menu to run,
      edit, save or delete
EDIT/RUN
 SL4A offers an environment
to edit and run scripts on the
   phone but really limited
USING ADB PUSH/PULL

• It’s
     easier to edit scripts on your computer using your favorite
  text editor and leverage the Android Debug Bridge (ADB) to
  load them on the phone.

• ADB    is installed on /<android_sdk_folder>/platform-tool/
  •   adb pull /mnt/sdcard/sl4a/scripts/Camera.js ~/Documents/
      sl4a_scripts/

  •   adb push ~/Documents/sl4a_scripts/Camera.js /mnt/sdcard/sl4a/
      scripts
HELLO WORLD (PYTHON)


import android
droid = android.Android()
droid.makeToast('Hello,
Android!')
print 'Hello world!'
TAKING A PICTURE (JS)

load("/sdcard/
com.googlecode.rhinoforandroid/extras/rhino/
android.js");

var droid = new Android();

result = droid.cameraCapturePicture("/mnt/
sdcard/sl4a/pic.jpg", true);
WIFI
List all surrounding WiFi
   networks and their
connection information
LISTING WIFI NETWORKS (JS)
load("/sdcard/com.googlecode.rhinoforandroid/extras/rhino/
android.js");
var droid = new Android();
wifi_on = droid.checkWifiState();
if (wifi_on) {
    success = droid.wifiStartScan();
    if (success) {
         list_of_networks = droid.wifiGetScanResults();
         for (var i = 0; i < list_of_networks.length; i++) {
             for (attr in list_of_networks[i]) {
                 print(attr + ": " + list_of_networks[i][attr]);
             }
             print("n");
         }
    }
    droid.makeToast("Done obtaining list of WiFi networks!");
} else {
    droid.makeToast("WiFi radio is off");
}
USING GPS AND SMS (RUBY)
require "android";
def get_location(droid)
    droid.startLocating()
    droid.eventWaitFor("location")
    raw_location = droid.readLocation()
    droid.stopLocating()
    return raw_location["result"]["network"]
end

def format_address(loc_info)
    return loc_info["feature_name"] + " " + loc_info["thoroughfare"] + " " +
        loc_info["locality"] + ", " + loc_info["admin_area"] + " " +
        loc_info["postal_code"]
end

def get_address(droid, location)
    loc_info= droid.geocode(location["latitude"], location["longitude"])
    return format_address(loc_info["result"][0])
end

droid = Android.new
location = get_location droid
address = get_address droid, location
phone = droid.pickPhone
droid.smsSend phone["result"], "Greetings from SL4A, I'm at " + address
puts "done sending SMS with location"
BASIC UI
SL4A provides basic Android
  UI elements to be used in
scripts. But these UI elements
  are generally very limited
USING NATIVE TYPES AND
        LIBRARIES
import android
from datetime import date

droid = android.Android()
today = date.today()
droid.dialogCreateDatePicker(today.year, today.month, today.day)
droid.dialogShow()
selectedDate = droid.dialogGetResponse().result
first_date = date(selectedDate['year'], selectedDate['month'], selectedDate['day'])

droid.dialogCreateDatePicker(today.year, today.month, today.day)
droid.dialogShow()
selectedDate = droid.dialogGetResponse().result
second_date = date(selectedDate['year'], selectedDate['month'], selectedDate['day'])
timediff = abs(first_date - second_date)

droid.dialogCreateAlert("Difference", "Days: " + str(timediff.days))
droid.dialogSetPositiveButtonText('OK')
droid.dialogShow()
SIMPLE TWITTER CLIENT
                (RUBY)
require 'android'
require 'net/http'

droid = Android.new
url = URI.parse("http://twitter.com/statuses/update.xml")
req = Net::HTTP::Post.new(url.path)

req.basic_auth('user', 'password')
status = droid.getInput 'Twitter Update', "What's going on?"
req.set_form_data({'status' => status["result"],
                   'source' => 'Android'})

response = Net::HTTP.new(url.host, url.port).start do |http|
    http.request(req)
end

if response.code == "200"
  droid.makeToast "Your toot was successfully sent."
end
WEBVIEWS AS ADVANCED UI
<html>
  <head>
    <title>Text to Speech</title>
    <script>
       var droid = new Android();
       var speak = function() {
         droid.eventPost("say",
document.getElementById("say").value);
       }
    </script>
  </head>
  <body>
    <form onsubmit="speak(); return false;">
       <label for="say">What would you like to say?</
label>
       <input type="text" id="say" />
       <input type="submit" value="Speak" />
    </form>
  </body>
</html>
BACKGROUND SERVICE
You can create a background service that acts as a controller in
you favorite language to support your Web UI

 import android

 droid = android.Android()
 droid.webViewShow('file:///sdcard/sl4a/scripts/
 text_to_speech.html')
 while True:
     result = droid.eventWaitFor('say').result
     if result is not None:
         droid.ttsSpeak(result['data'])
ADVANCED SCRIPTS
• Python   is by far the most
  complete language on SL4A
• You can import more advanced
  libraries that are not part of the
  Python Standard Library.
• Like PyBluez for Bluetooth
• Or Twisted
  •   Twisted is an extremely powerful event-
      driven networking engine written in
      Python.
  •   Projects like BitTorrent and Launchpad
      use twisted as their networking engine.
PACKAGING YOU APP FOR
      THE GOOGLE PLAY STORE
•   For this step you will need Eclipse :(
•   Download the skeleton Android project from here:
    http://android-scripting.googlecode.com/hg/android/
    script_for_android_template.zip
•   Follow these instructions to configure the project:
    http://code.google.com/p/android-scripting/wiki/SharingScripts
•   Make sure you can generate an APK and do a test install.
•   Follow these instructions to sign your APK:
    http://developer.android.com/guide/publishing/app-signing.html
•   Viola! you can upload your APK to the Play Store
THAT’S IT FOR ME!
Thanks
To Our Sponsors
BEGINNERS PYTHON
                    WORKSHOP
•   The Beginners Python Workshop is a 2-day free event focused on
    teaching the basics of programming in the Python language.
•   Everybody is encouraged to attend, regardless of your previous
    experience with programming
•   The only requirements to attend are a laptop and a willingness to learn.
•   When:
    Friday, June 22nd 6pm - 10pm
    Saturday, June 23rd 10am - 4pm
•   Where:
    UMKC Campus 302 Flarsheim Hall
    5110 Rockhill Road, Kansas City, MO
            RSVP at: http://www.meetup.com/pythonkc/events/62339552
@_JUANDG
http://speakerdeck.com/u/juandg/p/androidscripting_kcdc2012#

More Related Content

What's hot

Using google appengine
Using google appengineUsing google appengine
Using google appengineWei Sun
 
Cordova 101
Cordova 101Cordova 101
Cordova 101
Rob Dudley
 
How we integrate & deploy Mobile Apps with Travis CI part 2
How we integrate & deploy Mobile Apps with Travis CI part 2How we integrate & deploy Mobile Apps with Travis CI part 2
How we integrate & deploy Mobile Apps with Travis CI part 2
Marcio Klepacz
 
Gdg ionic 2
Gdg ionic 2Gdg ionic 2
Gdg ionic 2
Shang Yi Lim
 
HotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePushHotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePushEvan Schultz
 
Agility Requires Safety
Agility Requires SafetyAgility Requires Safety
Agility Requires Safety
Yevgeniy Brikman
 
Ionic CLI Adventures
Ionic CLI AdventuresIonic CLI Adventures
Ionic CLI Adventures
Juarez Filho
 
Writing REST APIs with OpenAPI and Swagger Ada
Writing REST APIs with OpenAPI and Swagger AdaWriting REST APIs with OpenAPI and Swagger Ada
Writing REST APIs with OpenAPI and Swagger Ada
Stephane Carrez
 
Writing automation tests with python selenium behave pageobjects
Writing automation tests with python selenium behave pageobjectsWriting automation tests with python selenium behave pageobjects
Writing automation tests with python selenium behave pageobjects
Leticia Rss
 
Continuous Integration of Mobile Apps with Docker and Appium
Continuous Integration of Mobile Apps with Docker and AppiumContinuous Integration of Mobile Apps with Docker and Appium
Continuous Integration of Mobile Apps with Docker and Appium
Emergya
 
Ane for 9ria_cn
Ane for 9ria_cnAne for 9ria_cn
Ane for 9ria_cn
sonicxs
 
React native development with expo
React native development with expoReact native development with expo
React native development with expo
SangSun Park
 
Mastering Grails 3 Plugins - G3 Summit 2016
Mastering Grails 3 Plugins - G3 Summit 2016Mastering Grails 3 Plugins - G3 Summit 2016
Mastering Grails 3 Plugins - G3 Summit 2016
Alvaro Sanchez-Mariscal
 
Deploy Angular to the Cloud (ngBucharest)
Deploy Angular to the Cloud (ngBucharest)Deploy Angular to the Cloud (ngBucharest)
Deploy Angular to the Cloud (ngBucharest)
Simona Cotin
 
Drone Continuous Integration
Drone Continuous IntegrationDrone Continuous Integration
Drone Continuous Integration
Daniel Cerecedo
 
Scale your Magento app with Elastic Beanstalk
Scale your Magento app with Elastic BeanstalkScale your Magento app with Elastic Beanstalk
Scale your Magento app with Elastic Beanstalk
Corley S.r.l.
 
Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0
Micah Wood
 
Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...
Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...
Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...
Alvaro Sanchez-Mariscal
 

What's hot (20)

Using google appengine
Using google appengineUsing google appengine
Using google appengine
 
Cordova 101
Cordova 101Cordova 101
Cordova 101
 
How we integrate & deploy Mobile Apps with Travis CI part 2
How we integrate & deploy Mobile Apps with Travis CI part 2How we integrate & deploy Mobile Apps with Travis CI part 2
How we integrate & deploy Mobile Apps with Travis CI part 2
 
Gdg ionic 2
Gdg ionic 2Gdg ionic 2
Gdg ionic 2
 
HotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePushHotPush with Ionic 2 and CodePush
HotPush with Ionic 2 and CodePush
 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
 
Agility Requires Safety
Agility Requires SafetyAgility Requires Safety
Agility Requires Safety
 
Ionic CLI Adventures
Ionic CLI AdventuresIonic CLI Adventures
Ionic CLI Adventures
 
Writing REST APIs with OpenAPI and Swagger Ada
Writing REST APIs with OpenAPI and Swagger AdaWriting REST APIs with OpenAPI and Swagger Ada
Writing REST APIs with OpenAPI and Swagger Ada
 
Writing automation tests with python selenium behave pageobjects
Writing automation tests with python selenium behave pageobjectsWriting automation tests with python selenium behave pageobjects
Writing automation tests with python selenium behave pageobjects
 
Continuous Integration of Mobile Apps with Docker and Appium
Continuous Integration of Mobile Apps with Docker and AppiumContinuous Integration of Mobile Apps with Docker and Appium
Continuous Integration of Mobile Apps with Docker and Appium
 
Ane for 9ria_cn
Ane for 9ria_cnAne for 9ria_cn
Ane for 9ria_cn
 
React native development with expo
React native development with expoReact native development with expo
React native development with expo
 
Mastering Grails 3 Plugins - G3 Summit 2016
Mastering Grails 3 Plugins - G3 Summit 2016Mastering Grails 3 Plugins - G3 Summit 2016
Mastering Grails 3 Plugins - G3 Summit 2016
 
Deploy Angular to the Cloud (ngBucharest)
Deploy Angular to the Cloud (ngBucharest)Deploy Angular to the Cloud (ngBucharest)
Deploy Angular to the Cloud (ngBucharest)
 
Drone Continuous Integration
Drone Continuous IntegrationDrone Continuous Integration
Drone Continuous Integration
 
Cocoa pods
Cocoa podsCocoa pods
Cocoa pods
 
Scale your Magento app with Elastic Beanstalk
Scale your Magento app with Elastic BeanstalkScale your Magento app with Elastic Beanstalk
Scale your Magento app with Elastic Beanstalk
 
Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0
 
Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...
Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...
Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...
 

Similar to Android Scripting

Android dev o_auth
Android dev o_authAndroid dev o_auth
Android dev o_auth
lzongren
 
Cross-platform Mobile Development on Open Source
Cross-platform Mobile Development on Open SourceCross-platform Mobile Development on Open Source
Cross-platform Mobile Development on Open Source
All Things Open
 
Seminar on android app development
Seminar on android app developmentSeminar on android app development
Seminar on android app development
AbhishekKumar4779
 
Building Cross-Platform Mobile Apps
Building Cross-Platform Mobile AppsBuilding Cross-Platform Mobile Apps
Building Cross-Platform Mobile Apps
Troy Miles
 
Intro to android (gdays)
Intro to android (gdays)Intro to android (gdays)
Intro to android (gdays)
Omolara Adejuwon
 
Android - Anroid Pproject
Android - Anroid PprojectAndroid - Anroid Pproject
Android - Anroid Pproject
Vibrant Technologies & Computers
 
Aandroid
AandroidAandroid
Aandroid
jyoti_prakash
 
Introduction to android mobile app development.pptx
Introduction to android mobile app development.pptxIntroduction to android mobile app development.pptx
Introduction to android mobile app development.pptx
ridzah12
 
Cross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual StudioCross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual StudioMizanur Sarker
 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
Junda Ong
 
Android Application Development Training by NITIN GUPTA
Android Application Development Training by NITIN GUPTA Android Application Development Training by NITIN GUPTA
Android Application Development Training by NITIN GUPTA
NITIN GUPTA
 
Getting started with android programming
Getting started with android programmingGetting started with android programming
Getting started with android programming
PERKYTORIALS
 
Android Seminar || history || versions||application developement
Android Seminar || history || versions||application developement Android Seminar || history || versions||application developement
Android Seminar || history || versions||application developement
Shubham Pahune
 
Building Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGap
Building Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGapBuilding Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGap
Building Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGap
Nick Landry
 
Slides bootcamp21
Slides bootcamp21Slides bootcamp21
Slides bootcamp21
dxsaki
 
Android
AndroidAndroid
Android
Tapan Khilar
 
[2015/2016] Apache Cordova
[2015/2016] Apache Cordova[2015/2016] Apache Cordova
[2015/2016] Apache Cordova
Ivano Malavolta
 

Similar to Android Scripting (20)

Talk (2)
Talk (2)Talk (2)
Talk (2)
 
Android dev o_auth
Android dev o_authAndroid dev o_auth
Android dev o_auth
 
Cross-platform Mobile Development on Open Source
Cross-platform Mobile Development on Open SourceCross-platform Mobile Development on Open Source
Cross-platform Mobile Development on Open Source
 
Seminar on android app development
Seminar on android app developmentSeminar on android app development
Seminar on android app development
 
Building Cross-Platform Mobile Apps
Building Cross-Platform Mobile AppsBuilding Cross-Platform Mobile Apps
Building Cross-Platform Mobile Apps
 
Intro to android (gdays)
Intro to android (gdays)Intro to android (gdays)
Intro to android (gdays)
 
Android - Anroid Pproject
Android - Anroid PprojectAndroid - Anroid Pproject
Android - Anroid Pproject
 
Aandroid
AandroidAandroid
Aandroid
 
Introduction to android mobile app development.pptx
Introduction to android mobile app development.pptxIntroduction to android mobile app development.pptx
Introduction to android mobile app development.pptx
 
Cross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual StudioCross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual Studio
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
 
Android Application Development Training by NITIN GUPTA
Android Application Development Training by NITIN GUPTA Android Application Development Training by NITIN GUPTA
Android Application Development Training by NITIN GUPTA
 
Getting started with android programming
Getting started with android programmingGetting started with android programming
Getting started with android programming
 
Android Seminar || history || versions||application developement
Android Seminar || history || versions||application developement Android Seminar || history || versions||application developement
Android Seminar || history || versions||application developement
 
Building Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGap
Building Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGapBuilding Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGap
Building Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGap
 
Slides bootcamp21
Slides bootcamp21Slides bootcamp21
Slides bootcamp21
 
Android
AndroidAndroid
Android
 
[2015/2016] Apache Cordova
[2015/2016] Apache Cordova[2015/2016] Apache Cordova
[2015/2016] Apache Cordova
 
Android Apps
Android AppsAndroid Apps
Android Apps
 

More from Juan Gomez

App Indexing: Blurring the Lines Between Your Website and App
App Indexing: Blurring the Lines Between Your Website and AppApp Indexing: Blurring the Lines Between Your Website and App
App Indexing: Blurring the Lines Between Your Website and App
Juan Gomez
 
REST is not enough: Using Push Notifications to better support your mobile cl...
REST is not enough: Using Push Notifications to better support your mobile cl...REST is not enough: Using Push Notifications to better support your mobile cl...
REST is not enough: Using Push Notifications to better support your mobile cl...
Juan Gomez
 
Beating Android Fragmentation
Beating Android FragmentationBeating Android Fragmentation
Beating Android Fragmentation
Juan Gomez
 
Effective Android Messaging
Effective Android MessagingEffective Android Messaging
Effective Android Messaging
Juan Gomez
 
Teach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry PiTeach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry Pi
Juan Gomez
 
Gae icc fall2011
Gae icc fall2011Gae icc fall2011
Gae icc fall2011Juan Gomez
 

More from Juan Gomez (6)

App Indexing: Blurring the Lines Between Your Website and App
App Indexing: Blurring the Lines Between Your Website and AppApp Indexing: Blurring the Lines Between Your Website and App
App Indexing: Blurring the Lines Between Your Website and App
 
REST is not enough: Using Push Notifications to better support your mobile cl...
REST is not enough: Using Push Notifications to better support your mobile cl...REST is not enough: Using Push Notifications to better support your mobile cl...
REST is not enough: Using Push Notifications to better support your mobile cl...
 
Beating Android Fragmentation
Beating Android FragmentationBeating Android Fragmentation
Beating Android Fragmentation
 
Effective Android Messaging
Effective Android MessagingEffective Android Messaging
Effective Android Messaging
 
Teach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry PiTeach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry Pi
 
Gae icc fall2011
Gae icc fall2011Gae icc fall2011
Gae icc fall2011
 

Recently uploaded

Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 

Recently uploaded (20)

Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 

Android Scripting

  • 1. ANDROID SCRIPTING A Java-less approach to building apps Juan Gomez Android Dev @ Handmark, Inc Co-founder PythonKC
  • 2. AGENDA • Android 101 • Scripting Layer for Android (SL4A) • Basic tasks (WiFi, GPS, camera, SMS) and basic UI • Using WebViews and Javascript for better UIs • Advanced Scripts (Twisted, PyBluez) • Packaging your scripts on an APK • Q&A
  • 3. ANDROID 101 An Android application is actually a collection of several components, each defined in a file called AndroidManifest.xml The 4 main types of components are: • Activities • Services • Content Providers • Broadcast Receivers Apps are packaged on an APK file (myApp.apk)
  • 4. INTENTS • Apps can communicate with each other by providing and consuming each other’s Intents • Intents “link” activities, services, and receivers together • Intents consists of • An action (i.e. ACTION_VIEW) • Categories (i.e. CATEGORY_DEFAULT) • A URI (i.e. content://contacts/people/123) • “Extras” metadata • Intents can also be sent to hard-coded class names (com.foo.FooActivity)
  • 5. HOW DO I GET STARTED? • Download the Android SDK: http://developer.android.com/sdk • Add Android platforms and other packages to your SDK • Install the ADT plug-in for Eclipse (optional) • Enable app side-loading on your phone: • Settings > Application > Unknown Sources
  • 6. WHERE CAN I LEARN MORE? • Android’s Dev Guide http://developer.android.com/guide • Lots of Android Books • StackOverflow • Recommended resource: • http://commonsware.com/ • The Busy Coder’s Guide to Android Development • Yearly subscription
  • 7. SCRIPTING LAYER FOR ANDROID (SL4A) • Brings scripting languages to Android • Allows you to edit and execute scripts and interactive interpreters directly on the Android device. • Scripts have access to many of the APIs available to full- fledged Android apps. • Supported languages include: Python, Perl, JRuby, Lua, BeanShell, JavaScript and Tcl • There’s limited support for PHP and Shell scripts
  • 8. SL4A ARCHITECTURE • As it name implies, SL4A sits between the actual Android JVM (Dalvik) and the executable Scripts. • The Facade API exposes a subset of Android system API's via JSON RPC calls • Only the parts of Android's APIs which has been wrapped by facades are available to interpreter • This is a fundamental feature of SL4A added by Google to avoid security concerns.
  • 9. WHAT CAN SL4A DO? • Handle intents • Start activities • Make phone calls • Send text messages • Scan bar codes • Poll location and sensor data • Use text-to-speech
  • 10. HOW TO DOWNLOAD? • Go to: http://code.google.com/p/android-scripting/
  • 11. HOW TO USE IT? SL4A installs as an App on your phone, you need to install separate interpreters for each language you want to use
  • 12. INTERPRETERS Open up the App, click on Menu > View > Interpreters to get a list of the available interpreters
  • 13. DOWNLOAD Click on Menu > Add to get a list of new interpreters you can install on your phone
  • 14. INSTALL Click on an Interpreter from the list and this will download an .APK with the installer.
  • 15. SCRIPTS When you open the SL4A app you get a list of your available scripts. You can use a quick action menu to run, edit, save or delete
  • 16. EDIT/RUN SL4A offers an environment to edit and run scripts on the phone but really limited
  • 17. USING ADB PUSH/PULL • It’s easier to edit scripts on your computer using your favorite text editor and leverage the Android Debug Bridge (ADB) to load them on the phone. • ADB is installed on /<android_sdk_folder>/platform-tool/ • adb pull /mnt/sdcard/sl4a/scripts/Camera.js ~/Documents/ sl4a_scripts/ • adb push ~/Documents/sl4a_scripts/Camera.js /mnt/sdcard/sl4a/ scripts
  • 18.
  • 19. HELLO WORLD (PYTHON) import android droid = android.Android() droid.makeToast('Hello, Android!') print 'Hello world!'
  • 20. TAKING A PICTURE (JS) load("/sdcard/ com.googlecode.rhinoforandroid/extras/rhino/ android.js"); var droid = new Android(); result = droid.cameraCapturePicture("/mnt/ sdcard/sl4a/pic.jpg", true);
  • 21. WIFI List all surrounding WiFi networks and their connection information
  • 22. LISTING WIFI NETWORKS (JS) load("/sdcard/com.googlecode.rhinoforandroid/extras/rhino/ android.js"); var droid = new Android(); wifi_on = droid.checkWifiState(); if (wifi_on) { success = droid.wifiStartScan(); if (success) { list_of_networks = droid.wifiGetScanResults(); for (var i = 0; i < list_of_networks.length; i++) { for (attr in list_of_networks[i]) { print(attr + ": " + list_of_networks[i][attr]); } print("n"); } } droid.makeToast("Done obtaining list of WiFi networks!"); } else { droid.makeToast("WiFi radio is off"); }
  • 23. USING GPS AND SMS (RUBY) require "android"; def get_location(droid) droid.startLocating() droid.eventWaitFor("location") raw_location = droid.readLocation() droid.stopLocating() return raw_location["result"]["network"] end def format_address(loc_info) return loc_info["feature_name"] + " " + loc_info["thoroughfare"] + " " + loc_info["locality"] + ", " + loc_info["admin_area"] + " " + loc_info["postal_code"] end def get_address(droid, location) loc_info= droid.geocode(location["latitude"], location["longitude"]) return format_address(loc_info["result"][0]) end droid = Android.new location = get_location droid address = get_address droid, location phone = droid.pickPhone droid.smsSend phone["result"], "Greetings from SL4A, I'm at " + address puts "done sending SMS with location"
  • 24. BASIC UI SL4A provides basic Android UI elements to be used in scripts. But these UI elements are generally very limited
  • 25. USING NATIVE TYPES AND LIBRARIES import android from datetime import date droid = android.Android() today = date.today() droid.dialogCreateDatePicker(today.year, today.month, today.day) droid.dialogShow() selectedDate = droid.dialogGetResponse().result first_date = date(selectedDate['year'], selectedDate['month'], selectedDate['day']) droid.dialogCreateDatePicker(today.year, today.month, today.day) droid.dialogShow() selectedDate = droid.dialogGetResponse().result second_date = date(selectedDate['year'], selectedDate['month'], selectedDate['day']) timediff = abs(first_date - second_date) droid.dialogCreateAlert("Difference", "Days: " + str(timediff.days)) droid.dialogSetPositiveButtonText('OK') droid.dialogShow()
  • 26. SIMPLE TWITTER CLIENT (RUBY) require 'android' require 'net/http' droid = Android.new url = URI.parse("http://twitter.com/statuses/update.xml") req = Net::HTTP::Post.new(url.path) req.basic_auth('user', 'password') status = droid.getInput 'Twitter Update', "What's going on?" req.set_form_data({'status' => status["result"], 'source' => 'Android'}) response = Net::HTTP.new(url.host, url.port).start do |http| http.request(req) end if response.code == "200" droid.makeToast "Your toot was successfully sent." end
  • 27. WEBVIEWS AS ADVANCED UI <html> <head> <title>Text to Speech</title> <script> var droid = new Android(); var speak = function() { droid.eventPost("say", document.getElementById("say").value); } </script> </head> <body> <form onsubmit="speak(); return false;"> <label for="say">What would you like to say?</ label> <input type="text" id="say" /> <input type="submit" value="Speak" /> </form> </body> </html>
  • 28. BACKGROUND SERVICE You can create a background service that acts as a controller in you favorite language to support your Web UI import android droid = android.Android() droid.webViewShow('file:///sdcard/sl4a/scripts/ text_to_speech.html') while True: result = droid.eventWaitFor('say').result if result is not None: droid.ttsSpeak(result['data'])
  • 29. ADVANCED SCRIPTS • Python is by far the most complete language on SL4A • You can import more advanced libraries that are not part of the Python Standard Library. • Like PyBluez for Bluetooth • Or Twisted • Twisted is an extremely powerful event- driven networking engine written in Python. • Projects like BitTorrent and Launchpad use twisted as their networking engine.
  • 30. PACKAGING YOU APP FOR THE GOOGLE PLAY STORE • For this step you will need Eclipse :( • Download the skeleton Android project from here: http://android-scripting.googlecode.com/hg/android/ script_for_android_template.zip • Follow these instructions to configure the project: http://code.google.com/p/android-scripting/wiki/SharingScripts • Make sure you can generate an APK and do a test install. • Follow these instructions to sign your APK: http://developer.android.com/guide/publishing/app-signing.html • Viola! you can upload your APK to the Play Store
  • 33. BEGINNERS PYTHON WORKSHOP • The Beginners Python Workshop is a 2-day free event focused on teaching the basics of programming in the Python language. • Everybody is encouraged to attend, regardless of your previous experience with programming • The only requirements to attend are a laptop and a willingness to learn. • When: Friday, June 22nd 6pm - 10pm Saturday, June 23rd 10am - 4pm • Where: UMKC Campus 302 Flarsheim Hall 5110 Rockhill Road, Kansas City, MO RSVP at: http://www.meetup.com/pythonkc/events/62339552

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n