SlideShare una empresa de Scribd logo
1 de 37
ANDROID
OPEN ACCESSORY
APIs
Pearl Chen
Google+: gplus.to/pearl
Twitter: @androidsNsheep
Slides: slideshare.net/androidsNsheep
WHAT IS AN OPEN ACCESSORY?


A device that can become a
USB Host while connected
to an Android phone or
tablet.
WHAT DOES THE USB HOST DO?
It keeps track of plugged in devices
and controls data traffic. It also
supplies devices with power.
Data transfer is 2-way but the USB
protocol is asymmetrical; there can
be multiple devices but only one
host.
   mouse                 game controller


 keyboard                webcam
WHERE DOES ANDROID FIT?
Not all Android phones can host.
(Most tablets do though.)

To work around this, Google flips it
on its head and instead: Android
becomes the device/accessory.

 phone                         tablet

    mouse                   game controller


  keyboard                  webcam
ANDROID DEVELOPMENT KIT (ADK)

The ADK is a specialized USB Host
running ADK firmware that can
communicate with Android apps that
implement Open Accessory APIs.
The Arduino Mega ADK is the most
well-known version of an ADK.
ANDROID DEVELOPMENT KIT (ADK)

But other ADKs exist too!
Board schematics and source
code is open source. (Creative
Commons and Apache 2.0 licenses.)
DEMO #1
FIRMWARE CODE
Sample ADK “firmware” (translation:
an Arduino sketch) is downloadable
at developer.android.com.


But if you don’t have the
Accessory Demo Shield
they gave out at Google
IO 2011, it won’t work. :(
SIMPLIFIED-VERSION OF FIRMWARE

Stripped down version:
iheartrobotics.com/2011/07/
arduino-mega-adk-setup-
notes.html

(Simply turns on/off built-in LED on pin 13 of the
Arduino when told to by the app running on the
Android device.)
CORE OF FIRMWARE
#include <Max3421e.h>
#include <Usb.h>
#include <AndroidAccessory.h>

AndroidAccessory acc("Google, Inc.",
                     "DemoKit",
                     "DemoKit Arduino Board",
                     "1.0",
                     "http://www.android.com",
                     "0000000012345678");
...




Include any required classes and create a new instance of an
AndroidAccessory , passing in parameters for:
manufacturer, model, description, version, uri, and serial #
CORE OF FIRMWARE
...


void setup() {
      ...

      acc.powerOn();
}

void loop() {
      ...

      if (acc.isConnected()) {
            //communicate with your Android application here
      }
      else {
            //optional but recommended:
            //set the accessory to its default state
      }
      ...

}
ANDROID APP CODE

Sample DemoKit app is
downloadable at
developer.android.com.

You can more or less hijack the UI
screens and control widgets while
learning how to interface with the
Arduino.
ANDROID MANIFEST
Check that the device has USB capabilities so it
can’t be installed or show up in the Android
Market:

Phones with 2.3.4+
<uses-library android:name=
  "com.android.future.usb.accessory" />


Tablets with 3.1+
<uses-feature android:name=
  "android.hardware.usb.accessory" />
ANDROID MANIFEST
Set a target device version:

Phones with 2.3.4+
<uses-sdk android:minSdkVersion="10" />


Tablets with 3.1+:
<uses-sdk android:minSdkVersion="12" />
ANDROID MANIFEST
Add an intent filter so the popup dialog box will
show up when plugged into the Arduino:

<intent-filter>
  <action android:name=
     "android.hardware.usb.action.
        USB_ACCESSORY_ATTACHED" />
</intent-filter>
ANDROID MANIFEST
And let the app know what USB devices it
should be allowed to talk to:

<meta-data android:name=
  "android.hardware.usb.action.
     USB_ACCESSORY_ATTACHED“
   android:resource=
     "@xml/accessory_filter" />
ANDROID RESOURCE XML
res/xml/accessory_filter.xml contains:

<resources>
  <usb-accessory
    manufacturer="Google, Inc."
    model="DemoKit“
    version="1.0" />
</resources>

Remember from the Arduino firmware?
AndroidAccessory acc("Google, Inc.",
                       "DemoKit",
                       "DemoKit Arduino Board",
                       "1.0",
                       "http://www.android.com",
                       "0000000012345678");
DATA SENDING & RECEIVING
Open up a single FileInputStream and a single
FileOutputStream to send and receive arbitrary data. The
encoding format is defined by you.

public class UsbAccessoryActivity extends Activity {
    private FileInputStream mInput;
    private FileOutputStream mOutput;

    private void openAccessory() {
        UsbManager manager = UsbManager.getInstance(this);
        UsbAccessory accessory = UsbManager.getAccessory(getIntent());

        ParcelFileDescriptor fd = manager.openAccessory(accessory);

        if (fd != null) {
            mInput = new FileInputStream(fd);
            mOutput = new FileOutputStream(fd);
        } else {
            // Oh noes, the accessory didn’t open!
        }
    }
}
DATA SENDING & RECEIVING
DemoKit example chose to send and receive via byte arrays.

In RelayController.java:
mActivity.sendCommand(
  DemoKitActivity.RELAY_COMMAND,   //constant:   set to be 3
  mCommandTarget,                  //constant:   Relay1 button would be 0,
                                   //            Relay2 btn would be 1
  isChecked ? 1 : 0);              //variable:   on or off? 1 or 0?


In DemoKitActivity.java:
public void sendCommand(byte command, byte target, int value) {
  byte[] buffer = new byte[3];
  …
  buffer[0] = command;
  buffer[1] = target;
  buffer[2] = (byte) value;
  …
}
DATA SENDING & RECEIVING
Meanwhile, on the Arduino…

if (acc.isConnected()) {
    int len = acc.read(msg, sizeof(msg), 1);

    If (data[0] == 0x3) {         //a relay?
        if (data[1] == 0x0) {     // Relay1 button?
          digitalWrite(LED1, data[2] ? HIGH : LOW);}
      }
}
DEMO #2
PROJECT IDEAS


     What can you make with
     the Open Accessory APIs
     and an Arduino?

                 1+1=3
Things already
   available                       Super
on your phone     Electronics   awesome stuff!
                 components
                 you can add
AVAILABLE NEXUS S I/O



                  touch screen
MUSIC BETA: “NOW PLAYING”




                  Chris Juergen
 http://www.youtube.com/watch?v=v_bWOUUv8zo
AVAILABLE NEXUS S I/O



                  touch screen


                  camera
GARDEN MONITOR




                   Sam Steele
 http://www.youtube.com/watch?v=3GPnpmZnUjE
AVAILABLE NEXUS S I/O



                  touch screen


                  camera

                  wifi/3G
AVAILABLE NEXUS S I/O



accelerometer            touch screen


                         camera

                         wifi/3G
AVAILABLE NEXUS S I/O



accelerometer            touch screen


        GPS              camera

                         wifi/3G
AVAILABLE NEXUS S I/O



accelerometer           touch screen


       GPS              camera

mass storage            wifi/3G
BABY ROCKER POC




                   Ben Heck
 http://www.youtube.com/watch?v=inRWzFeLVko
AVAILABLE NEXUS S I/O



accelerometer            touch screen


         GPS             camera

mass storage             wifi/3G


proximity/light
      sensors
AVAILABLE NEXUS S I/O



accelerometer            touch screen


         GPS             camera

mass storage             wifi/3G

                         temperature
proximity/light          sensor
      sensors
NASA SPHERES




                     NASA
http://www.youtube.com/watch?v=REsEgrhmMjc#!
AVAILABLE NEXUS S I/O



accelerometer              touch screen


         GPS               camera

mass storage               wifi/3G

                           temperature
proximity/light            sensor
      sensors

              microphone
AVAILABLE NEXUS S I/O



accelerometer                    touch screen


         GPS                     camera

mass storage                     wifi/3G

                                 temperature
proximity/light                  sensor
      sensors

              microphone   NFC
BLURRING LINES




Asus Transformer and Padfone, Nook, Xperia PLAY

Más contenido relacionado

La actualidad más candente

Controlling an Arduino with Android
Controlling an Arduino with AndroidControlling an Arduino with Android
Controlling an Arduino with AndroidA. Hernandez
 
Go Green - Save Power
Go Green - Save PowerGo Green - Save Power
Go Green - Save PowerRajesh Sola
 
Connecting Arduino and Android
Connecting Arduino and AndroidConnecting Arduino and Android
Connecting Arduino and AndroidMichał Tuszyński
 
Android Things - The IoT platform from Google
Android Things - The IoT platform from GoogleAndroid Things - The IoT platform from Google
Android Things - The IoT platform from GoogleEmmanuel Obot
 
Arduino Programming Software Development
Arduino Programming Software DevelopmentArduino Programming Software Development
Arduino Programming Software DevelopmentSanjay Kumar
 
Android Things Linux Day 2017
Android Things Linux Day 2017 Android Things Linux Day 2017
Android Things Linux Day 2017 Stefano Sanna
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino동호 손
 
My arduino presentation
My arduino presentationMy arduino presentation
My arduino presentationSham Arsenal
 
Introduction to Internet of Things Hardware
Introduction to Internet of Things HardwareIntroduction to Internet of Things Hardware
Introduction to Internet of Things HardwareDaniel Eichhorn
 
Arduino technical session 1
Arduino technical session 1Arduino technical session 1
Arduino technical session 1Audiomas Soni
 
MicroEJ OS for IoT devices
MicroEJ OS for IoT devicesMicroEJ OS for IoT devices
MicroEJ OS for IoT devicescharlotte75009
 
Developing a NodeBot using Intel XDK IoT Edition
Developing a NodeBot using Intel XDK IoT EditionDeveloping a NodeBot using Intel XDK IoT Edition
Developing a NodeBot using Intel XDK IoT EditionIntel® Software
 
Zero to one with Android Things - Hieu Hua
Zero to one with Android Things - Hieu HuaZero to one with Android Things - Hieu Hua
Zero to one with Android Things - Hieu HuaTu Le Dinh
 
Android things introduction - Development for IoT
Android things introduction - Development for IoTAndroid things introduction - Development for IoT
Android things introduction - Development for IoTBartosz Kosarzycki
 

La actualidad más candente (20)

Controlling an Arduino with Android
Controlling an Arduino with AndroidControlling an Arduino with Android
Controlling an Arduino with Android
 
Go Green - Save Power
Go Green - Save PowerGo Green - Save Power
Go Green - Save Power
 
Android meets Arduino
Android meets ArduinoAndroid meets Arduino
Android meets Arduino
 
Connecting Arduino and Android
Connecting Arduino and AndroidConnecting Arduino and Android
Connecting Arduino and Android
 
Arduino day
Arduino dayArduino day
Arduino day
 
Android Things - The IoT platform from Google
Android Things - The IoT platform from GoogleAndroid Things - The IoT platform from Google
Android Things - The IoT platform from Google
 
Android Things
Android ThingsAndroid Things
Android Things
 
Arduino
ArduinoArduino
Arduino
 
Arduino Programming Software Development
Arduino Programming Software DevelopmentArduino Programming Software Development
Arduino Programming Software Development
 
Arduino
ArduinoArduino
Arduino
 
Android Things Linux Day 2017
Android Things Linux Day 2017 Android Things Linux Day 2017
Android Things Linux Day 2017
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
My arduino presentation
My arduino presentationMy arduino presentation
My arduino presentation
 
Introduction to Internet of Things Hardware
Introduction to Internet of Things HardwareIntroduction to Internet of Things Hardware
Introduction to Internet of Things Hardware
 
Arduino technical session 1
Arduino technical session 1Arduino technical session 1
Arduino technical session 1
 
MicroEJ OS for IoT devices
MicroEJ OS for IoT devicesMicroEJ OS for IoT devices
MicroEJ OS for IoT devices
 
Developing a NodeBot using Intel XDK IoT Edition
Developing a NodeBot using Intel XDK IoT EditionDeveloping a NodeBot using Intel XDK IoT Edition
Developing a NodeBot using Intel XDK IoT Edition
 
Zero to one with Android Things - Hieu Hua
Zero to one with Android Things - Hieu HuaZero to one with Android Things - Hieu Hua
Zero to one with Android Things - Hieu Hua
 
Android Things - The IoT platform for everyone.
Android Things - The IoT platform for everyone. Android Things - The IoT platform for everyone.
Android Things - The IoT platform for everyone.
 
Android things introduction - Development for IoT
Android things introduction - Development for IoTAndroid things introduction - Development for IoT
Android things introduction - Development for IoT
 

Similar a Android Open Accessory APIs

Better With Friends: Android+NFC+Arduino
Better With Friends: Android+NFC+ArduinoBetter With Friends: Android+NFC+Arduino
Better With Friends: Android+NFC+ArduinoPearl Chen
 
Droidcon Turin 2015 - Android wear sdk introduction
Droidcon Turin 2015 - Android wear sdk introductionDroidcon Turin 2015 - Android wear sdk introduction
Droidcon Turin 2015 - Android wear sdk introductionMichelantonio Trizio
 
Android wear SDK introduction
Android wear SDK introductionAndroid wear SDK introduction
Android wear SDK introductionTiziano Basile
 
Getting started with android dev and test perspective
Getting started with android   dev and test perspectiveGetting started with android   dev and test perspective
Getting started with android dev and test perspectiveGunjan Kumar
 
Developing AIR for Mobile with Flash Professional CS5.5
Developing AIR for Mobile with Flash Professional CS5.5Developing AIR for Mobile with Flash Professional CS5.5
Developing AIR for Mobile with Flash Professional CS5.5Chris Griffith
 
OzAltNet Fast-ANDroid-furious
OzAltNet Fast-ANDroid-furiousOzAltNet Fast-ANDroid-furious
OzAltNet Fast-ANDroid-furiousCraig Dunn
 
The Physical World meets the Web
The Physical World meets the WebThe Physical World meets the Web
The Physical World meets the WebMaximiliano Firtman
 
Programming objects with android
Programming objects with androidProgramming objects with android
Programming objects with androidfirenze-gtug
 
Flash runtime on mobile
Flash runtime on mobileFlash runtime on mobile
Flash runtime on mobilehoward-wu
 
Android Operating System
Android Operating SystemAndroid Operating System
Android Operating Systemrenoy reji
 
OzAltNet Fast-ANDroid-furious
OzAltNet Fast-ANDroid-furiousOzAltNet Fast-ANDroid-furious
OzAltNet Fast-ANDroid-furiousCraig Dunn
 
Mobile app development snovasys
Mobile app development   snovasysMobile app development   snovasys
Mobile app development snovasysxamarindevelopment
 
Synapseindia android application development tutorial
Synapseindia android application development tutorialSynapseindia android application development tutorial
Synapseindia android application development tutorialSynapseindiappsdevelopment
 
Synapseindia android apps development tutorial
Synapseindia android apps  development tutorialSynapseindia android apps  development tutorial
Synapseindia android apps development tutorialSynapseindiappsdevelopment
 
Augmented World Expo 2014 Wearable SDK Overview
Augmented World Expo 2014 Wearable SDK OverviewAugmented World Expo 2014 Wearable SDK Overview
Augmented World Expo 2014 Wearable SDK OverviewPatrick O'Shaughnessey
 
Overview of Android
Overview of AndroidOverview of Android
Overview of AndroidVicky Kumar
 
IoThings you don't even need to hack
IoThings you don't even need to hackIoThings you don't even need to hack
IoThings you don't even need to hackSlawomir Jasek
 

Similar a Android Open Accessory APIs (20)

Better With Friends: Android+NFC+Arduino
Better With Friends: Android+NFC+ArduinoBetter With Friends: Android+NFC+Arduino
Better With Friends: Android+NFC+Arduino
 
SensActions-Report
SensActions-ReportSensActions-Report
SensActions-Report
 
Android tutorial1
Android tutorial1Android tutorial1
Android tutorial1
 
Droidcon Turin 2015 - Android wear sdk introduction
Droidcon Turin 2015 - Android wear sdk introductionDroidcon Turin 2015 - Android wear sdk introduction
Droidcon Turin 2015 - Android wear sdk introduction
 
Android wear SDK introduction
Android wear SDK introductionAndroid wear SDK introduction
Android wear SDK introduction
 
Getting started with android dev and test perspective
Getting started with android   dev and test perspectiveGetting started with android   dev and test perspective
Getting started with android dev and test perspective
 
Developing AIR for Mobile with Flash Professional CS5.5
Developing AIR for Mobile with Flash Professional CS5.5Developing AIR for Mobile with Flash Professional CS5.5
Developing AIR for Mobile with Flash Professional CS5.5
 
Android report
Android reportAndroid report
Android report
 
OzAltNet Fast-ANDroid-furious
OzAltNet Fast-ANDroid-furiousOzAltNet Fast-ANDroid-furious
OzAltNet Fast-ANDroid-furious
 
The Physical World meets the Web
The Physical World meets the WebThe Physical World meets the Web
The Physical World meets the Web
 
Programming objects with android
Programming objects with androidProgramming objects with android
Programming objects with android
 
Flash runtime on mobile
Flash runtime on mobileFlash runtime on mobile
Flash runtime on mobile
 
Android Operating System
Android Operating SystemAndroid Operating System
Android Operating System
 
OzAltNet Fast-ANDroid-furious
OzAltNet Fast-ANDroid-furiousOzAltNet Fast-ANDroid-furious
OzAltNet Fast-ANDroid-furious
 
Mobile app development snovasys
Mobile app development   snovasysMobile app development   snovasys
Mobile app development snovasys
 
Synapseindia android application development tutorial
Synapseindia android application development tutorialSynapseindia android application development tutorial
Synapseindia android application development tutorial
 
Synapseindia android apps development tutorial
Synapseindia android apps  development tutorialSynapseindia android apps  development tutorial
Synapseindia android apps development tutorial
 
Augmented World Expo 2014 Wearable SDK Overview
Augmented World Expo 2014 Wearable SDK OverviewAugmented World Expo 2014 Wearable SDK Overview
Augmented World Expo 2014 Wearable SDK Overview
 
Overview of Android
Overview of AndroidOverview of Android
Overview of Android
 
IoThings you don't even need to hack
IoThings you don't even need to hackIoThings you don't even need to hack
IoThings you don't even need to hack
 

Último

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 

Último (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 

Android Open Accessory APIs

  • 1. ANDROID OPEN ACCESSORY APIs Pearl Chen Google+: gplus.to/pearl Twitter: @androidsNsheep Slides: slideshare.net/androidsNsheep
  • 2. WHAT IS AN OPEN ACCESSORY? A device that can become a USB Host while connected to an Android phone or tablet.
  • 3. WHAT DOES THE USB HOST DO? It keeps track of plugged in devices and controls data traffic. It also supplies devices with power. Data transfer is 2-way but the USB protocol is asymmetrical; there can be multiple devices but only one host. mouse game controller keyboard webcam
  • 4. WHERE DOES ANDROID FIT? Not all Android phones can host. (Most tablets do though.) To work around this, Google flips it on its head and instead: Android becomes the device/accessory. phone tablet mouse game controller keyboard webcam
  • 5. ANDROID DEVELOPMENT KIT (ADK) The ADK is a specialized USB Host running ADK firmware that can communicate with Android apps that implement Open Accessory APIs. The Arduino Mega ADK is the most well-known version of an ADK.
  • 6. ANDROID DEVELOPMENT KIT (ADK) But other ADKs exist too! Board schematics and source code is open source. (Creative Commons and Apache 2.0 licenses.)
  • 8. FIRMWARE CODE Sample ADK “firmware” (translation: an Arduino sketch) is downloadable at developer.android.com. But if you don’t have the Accessory Demo Shield they gave out at Google IO 2011, it won’t work. :(
  • 9. SIMPLIFIED-VERSION OF FIRMWARE Stripped down version: iheartrobotics.com/2011/07/ arduino-mega-adk-setup- notes.html (Simply turns on/off built-in LED on pin 13 of the Arduino when told to by the app running on the Android device.)
  • 10. CORE OF FIRMWARE #include <Max3421e.h> #include <Usb.h> #include <AndroidAccessory.h> AndroidAccessory acc("Google, Inc.", "DemoKit", "DemoKit Arduino Board", "1.0", "http://www.android.com", "0000000012345678"); ... Include any required classes and create a new instance of an AndroidAccessory , passing in parameters for: manufacturer, model, description, version, uri, and serial #
  • 11. CORE OF FIRMWARE ... void setup() { ... acc.powerOn(); } void loop() { ... if (acc.isConnected()) { //communicate with your Android application here } else { //optional but recommended: //set the accessory to its default state } ... }
  • 12. ANDROID APP CODE Sample DemoKit app is downloadable at developer.android.com. You can more or less hijack the UI screens and control widgets while learning how to interface with the Arduino.
  • 13. ANDROID MANIFEST Check that the device has USB capabilities so it can’t be installed or show up in the Android Market: Phones with 2.3.4+ <uses-library android:name= "com.android.future.usb.accessory" /> Tablets with 3.1+ <uses-feature android:name= "android.hardware.usb.accessory" />
  • 14. ANDROID MANIFEST Set a target device version: Phones with 2.3.4+ <uses-sdk android:minSdkVersion="10" /> Tablets with 3.1+: <uses-sdk android:minSdkVersion="12" />
  • 15. ANDROID MANIFEST Add an intent filter so the popup dialog box will show up when plugged into the Arduino: <intent-filter> <action android:name= "android.hardware.usb.action. USB_ACCESSORY_ATTACHED" /> </intent-filter>
  • 16. ANDROID MANIFEST And let the app know what USB devices it should be allowed to talk to: <meta-data android:name= "android.hardware.usb.action. USB_ACCESSORY_ATTACHED“ android:resource= "@xml/accessory_filter" />
  • 17. ANDROID RESOURCE XML res/xml/accessory_filter.xml contains: <resources> <usb-accessory manufacturer="Google, Inc." model="DemoKit“ version="1.0" /> </resources> Remember from the Arduino firmware? AndroidAccessory acc("Google, Inc.", "DemoKit", "DemoKit Arduino Board", "1.0", "http://www.android.com", "0000000012345678");
  • 18. DATA SENDING & RECEIVING Open up a single FileInputStream and a single FileOutputStream to send and receive arbitrary data. The encoding format is defined by you. public class UsbAccessoryActivity extends Activity { private FileInputStream mInput; private FileOutputStream mOutput; private void openAccessory() { UsbManager manager = UsbManager.getInstance(this); UsbAccessory accessory = UsbManager.getAccessory(getIntent()); ParcelFileDescriptor fd = manager.openAccessory(accessory); if (fd != null) { mInput = new FileInputStream(fd); mOutput = new FileOutputStream(fd); } else { // Oh noes, the accessory didn’t open! } } }
  • 19. DATA SENDING & RECEIVING DemoKit example chose to send and receive via byte arrays. In RelayController.java: mActivity.sendCommand( DemoKitActivity.RELAY_COMMAND, //constant: set to be 3 mCommandTarget, //constant: Relay1 button would be 0, // Relay2 btn would be 1 isChecked ? 1 : 0); //variable: on or off? 1 or 0? In DemoKitActivity.java: public void sendCommand(byte command, byte target, int value) { byte[] buffer = new byte[3]; … buffer[0] = command; buffer[1] = target; buffer[2] = (byte) value; … }
  • 20. DATA SENDING & RECEIVING Meanwhile, on the Arduino… if (acc.isConnected()) { int len = acc.read(msg, sizeof(msg), 1); If (data[0] == 0x3) { //a relay? if (data[1] == 0x0) { // Relay1 button? digitalWrite(LED1, data[2] ? HIGH : LOW);} } }
  • 22. PROJECT IDEAS What can you make with the Open Accessory APIs and an Arduino? 1+1=3 Things already available Super on your phone Electronics awesome stuff! components you can add
  • 23. AVAILABLE NEXUS S I/O touch screen
  • 24. MUSIC BETA: “NOW PLAYING” Chris Juergen http://www.youtube.com/watch?v=v_bWOUUv8zo
  • 25. AVAILABLE NEXUS S I/O touch screen camera
  • 26. GARDEN MONITOR Sam Steele http://www.youtube.com/watch?v=3GPnpmZnUjE
  • 27. AVAILABLE NEXUS S I/O touch screen camera wifi/3G
  • 28. AVAILABLE NEXUS S I/O accelerometer touch screen camera wifi/3G
  • 29. AVAILABLE NEXUS S I/O accelerometer touch screen GPS camera wifi/3G
  • 30. AVAILABLE NEXUS S I/O accelerometer touch screen GPS camera mass storage wifi/3G
  • 31. BABY ROCKER POC Ben Heck http://www.youtube.com/watch?v=inRWzFeLVko
  • 32. AVAILABLE NEXUS S I/O accelerometer touch screen GPS camera mass storage wifi/3G proximity/light sensors
  • 33. AVAILABLE NEXUS S I/O accelerometer touch screen GPS camera mass storage wifi/3G temperature proximity/light sensor sensors
  • 34. NASA SPHERES NASA http://www.youtube.com/watch?v=REsEgrhmMjc#!
  • 35. AVAILABLE NEXUS S I/O accelerometer touch screen GPS camera mass storage wifi/3G temperature proximity/light sensor sensors microphone
  • 36. AVAILABLE NEXUS S I/O accelerometer touch screen GPS camera mass storage wifi/3G temperature proximity/light sensor sensors microphone NFC
  • 37. BLURRING LINES Asus Transformer and Padfone, Nook, Xperia PLAY

Notas del editor

  1. Example: PC desktopwith pheriphals
  2. “accessory mode”
  3. Arduino is two pieces – one is hardware and the other is software.This particular board is a variation of the Arduino Mega. A thing that makes this board special is that it has two USB ports on it. Going back to the whole USB Host thing, this board has the ability to be a USB Host which is the 1st most important thing to becoming an Android Development Kit.The 2nd important piece is that the brains of the Arduino needs to run custom firmware that can communicate with an Android app running on the phone or the tablet.
  4. Use an Android app that Google created for their developer conference. Turn an LED on/off on the Arduino using the Android app.
  5. Google offers a sample project via their developer portal BUT *whawha*, it just doesn’t work with a plain old Arduino Mega. Need to strip out all the unnecessary code.
  6. Unmodified DemoKit Android app from Google IO. Working with hardware, especially when it’s new to you, is like wearing two or three hats. You wear one hat when you are prototyping with the electronics and wiring stuff up. Then you switch to another hat to write the Arduino code. And, in this scenario, you switch over to another hat that’s deep in Eclipse which is your Android SDK environment.
  7. Version 10 is actually Android 2.3.3 but you must compile with the level 10 Google APIs so it has 2.3.4 capabilities. The phone version of the Open Accessory support is actually a backport from the tablet version. Version 12 is 3.1
  8. Also in your manifest, add an intent filter. That will give you the popup that appeared when we plugged in the phone to the Arduino.
  9. And lastly, for your manifest, let your app know what USB devices it can support.
  10. For this DemoKit app, the list for the meta-data tag is an xml file that declares one usb-accessory node.If the app is not already installed on the device, it will try to find it on the Android Market.
  11. The data written could be a simple identifying string or number. Or, if you have a lot of different parts, you could use a byte array.
  12. InDemoKit, it was a byte array with 3 slots. There were quite a few other components so Google set it up with constants identifying the type of interaction. 3 was the number assigned to Relays. And since we were clicking on the first Relay button, it already had a value of 0.When you toggle Relay1 button on, you send over the values 3, 0, and 1. When you toggle Relay1 button off, you send over the values 3, 0, 0.We didn’t use Relay2 but the values would have been 3, 1, 1 or 3, 1, 0.
  13. So then on the Arduino side, you parse through the byte array. Here it’s checking if the value at index 0 was 3, meaning that it was a relay as established by the Android app constants.Then the nested if checked if it was the first relay button.Finally, digitalWrite is an Arduino command to turn a pin on or off – either high or low.
  14. Create rich Uis that are dynamic. Think about ways that you might want to push outside of the boundaries of that screen. Thing about multi-screen experiences, or experiences which have sort of an ambient visualization quality to it.
  15. Photos (time-lapse?) being triggered by real world events.e.g. doggy door with a tilt sensor
  16. traffic data, finanical data, twitter data, just so much data available to reinvent.
  17. motion or orientation.
  18. location-based services. Mobile form factor!
  19. mass storage is a nice companion to most of these inputs but this opens up the ability for data logging over time.
  20. Ben Heck runs a tech show so his proof of concept was a baby rocker. He drove around, collected real-world information about how the car rocked and then made a proof of concept that played back the recorded data.
  21. Here’s a project that doesn’t yet use the Open Accessory APIs but NASA has these spheres that are deployed into space and the Nexus S is the brains on it because it was so easy to prototype.
  22. Android is being embedded into many unexpected devices. Android itself is open source so you could roll your own specialized hardware and software products. The form factors of devices are blurring too so the use of the ADK and the Open Accessory APIs are great for prototyping a future scenerio where customized devices will be very cheap to manufacturer, or an off-the-shelf phone will be only $50 or $100.