Roboter-Baukasten Einführung in Android Manfred Borzechowski LambdaLogic Informationssysteme GmbH Wir gratulieren Ihnen, daß Sie sich für einen Android-Baukasten entschieden haben • Volle Java-Sprachunterstützung • Reichhaltiges API • Breite Geräteauswahl • Vielfältige Möglichkeiten • Organizer, Social, Player, Recorder, Navigation, Spiele, Barcode Scanner, Stimmgerät, Taschenlampe, u.v.a.m. • Ideal für die Realisierung eigener Ideen Herbstcampus 2012 – Roboter-Baukasten 2 Verhaltensmaßregeln • Vermeiden Sie unnötige Instanziierungen • Heap für Ihre Prozesse begrenzt • Garbage Collection langsam • Vermeiden Sie häufige Schreibvorgänge • Unperformant wegen Flash-basiertem Speicher • Vermeiden Sie Blockierung des UI-Threads • „Die Anwendung reagiert nicht“ • Vermeiden Sie häufige Netzwerkzugriffe über den Mobilfunkbetreiber • Verbraucht hohe Akku-Leistung Herbstcampus 2012 – Roboter-Baukasten 3 Der Baukasten Laufzeitumgebung Activity Resourcen R View AndroidManifest.xml Platform IDE Java JDK Herbstcampus 2012 – Roboter-Baukasten Device Broadcast Receiver Service ContentProvider Emulator ADT AVD SDK 4 Die Bodenplatte: Ein Java JDK • Haushaltsübliche Version • (nicht mitgeliefert) • Nur für IDE und SDK • Android bringt sein eigenes „Java“ mit • Eigene Laufzeitklassen und Dalvik VM Java JDK Herbstcampus 2012 – Roboter-Baukasten 5 Das Android SDK • Bezugsquelle http://developer.android.com/sdk/ • Bei Bestellung angeben ob für Windows, Mac OS X, Linux • Bestandteile kontrollieren • Tools • SDK Manager • AVD Manager SDK SDK Manager tools AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 6 Der SDK Manager • Installieren und aktualisieren von • • • • Platformen und -Tools Dokumentation Quellen Ergänzende Bibliotheken platform-<n> SDK Manager docs SDK tools AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 7 Platform – android.jar java.applet java.awt.* java.lang.instrument java.lang.management java.rmi.* java.util.spi javax.accessibility javax.activation javax.activity javax.annotation javax.annotation.* javax.imageio.* javax.jws.* javax.lang.* javax.management.* javax.naming.* javax.print.* javax.rmi.* javax.sound.* javax.swing.* javax.tools.* javax.transaction.* javax.xml.soap javax.xml.stream.* javax.xml.crypto.* javax.xml.ws.* org.omg.* org.w3c.dom.bootstrap org.w3c.dom.events ) maps.jar SDK Manager junit.framework android.accessibilityservice junit.runner android.accounts java.awt.font android.app.* (3) java.beans android.appwidget java.io android.bluetooth java.lang android.content.* (3) java.lang.annotation android.database.* (2) java.lang.ref android.gesture java.lang.reflect android.graphics.* (3) java.math android.hardware java.net android.inputmethodservice java.nio.* (5) android.location java.security.* (5) android.media java.security.acl android.net.* (3) java.sql android.opengl java.text android.os java.util android.preference java.util.concurrent.* (3) android.provider java.util.jar android.sax java.util.logging android.service.wallpaper java.util.prefs android.speech java.util.regex android.speech.tts java.util.zip android.telephony.* (3) javax.crypto android.test.* (3) javax.crypto.interfaces android.text.* (5) javax.crypto.spec android.util javax.net android.view.* (4) javax.net.ssl android.webkit javax.security.* (5) android.widget javax.sql javax.microedition.khronos.opengles javax.xml.* (10) javax.microedition.khronos.egl org.apache.http.* (32) org.json platform-<n> docs android.jar SDK tools AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 8 Der AVD Manager • Erstellen Virtueller Devices • Images und Konfigurationen QVGA WQVGA400 WQVGA432 HVGA WVGA800 WVGA854 240x320 240x400 240x432 320x480 480x800 480x854 • Varianten von • • • • Bildschirmgröße Pixeldichte Hardwareausstattung Speicherkartengröße und -Inhalt maps.jar SDK Manager platform-<n> docs android.jar SDK AVD WVGA800 tools AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 9 Emulator • Führt ein AVD aus • Aber langsam Emulator Screen (Telefon) LAN SD-Card maps.jar SDK Manager platform-<n> docs android.jar SDK AVD tools AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 10 Mit Smartphone/Tablet entwickeln Device Screen Sensoren • Geeignete USB-Treiber installieren GPS Camera • Am Gerät • • • • Telefon Einstellungen > Anwendungen > Entwicklung > USB-Debugging aktivieren WLAN SD-Card Emulator Screen (Telefon) LAN SD-Card maps.jar SDK Manager platform-<n> docs android.jar SDK AVD tools AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 11 ADB – Android Debug Bridge Device Screen Sensoren • Für Kommunikation mit Emulatoren und echten Geräten GPS Camera • Deviceliste • Logausgaben Telefon WLAN SD-Card Emulator Screen • Shell • Dateiaustausch • (De)Installation von Apps maps.jar (Telefon) LAN SD-Card platform-<n> android.jar adb shell SDK Manager docs SDK tools AVD logcat AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 12 IDE – Unterstützung Device Screen Sensoren • Für alle namhaften IDEs • Für Eclipse direkt von Google GPS Camera • ADT – Android Developer Tools Telefon WLAN SD-Card Emulator Screen (Telefon) LAN SD-Card IDE Eclipse + ADT IntelliJ IDEA NetBeans maps.jar SDK Manager platform-<n> docs android.jar SDK adb tools AVD AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 13 Die AndroidManifest.xml Device Screen Sensoren • Identifizierung GPS • Package Camera • Voraussetzungen Telefon • Hardware • Berechtigungen • Versionen WLAN SD-Card Emulator Emulator • Bestandteile Screen (Telefon) LAN AndroidManifest.xml IDE Eclipse + ADT IntelliJ IDEA NetBeans maps.jar SDK Manager uses-sdk requires-feature uses-permission platform-<n> docs android.jar SDK SD-Card adb tools AVD AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 14 View Device Screen • Oberflächen und -elemente Sensoren GPS • Layouts • Widgets • CustomViews Camera Telefon WLAN SD-Card • WYSIWYG Emulator View Screen IDE Eclipse + ADT IntelliJ IDEA NetBeans (Telefon) LAN AndroidManifest.xml maps.jar SDK Manager uses-sdk requires-feature uses-permission platform-<n> docs android.jar SDK SD-Card adb tools AVD AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 15 Ressourcen • Arten: Ressourcen Activity Texte, Bilder, • ActionBar Lifecycle Operations Layouts, Menüs, Dialog Bundle Farben, Größen, Menu Event Listener Animationen Content anim menu xml values values-en drawable-mdpi drawable-hdpi drawable View • Varianten: IDE Eclipse + ADT View layout-land layout IntelliJ IDEA NetBeans Short Operations • Sprache, Land, Auflösung, Größe, uses-sdk Orientierung, Version requires-featureuses-permission AndroidManifest.xml maps.jar SDK Manager platform-<n> docs android.jar SDK adb tools AVD AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 16 R Device • Zugriff auf Ressourcen Screen • Auswahl zur Laufzeit abhängig von Konfiguration Ressourcen Sensoren GPS Camera anim menu values values-en Telefon R xml WLAN SD-Card drawable-mdpi drawable-hdpi drawable Emulator layout-land IDE Eclipse + ADT View layout Screen IntelliJ IDEA NetBeans (Telefon) LAN AndroidManifest.xml maps.jar SDK Manager uses-sdk requires-feature uses-permission platform-<n> docs android.jar SDK SD-Card adb tools AVD AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 17 • Für User Interface verantwortlich Activity Launcher Ressourcen Activity ActionBar menu values values-en Dialog R xml Screen Sensoren onCreate • Was ist zu sehen? • Content View • Action Bar? Lifecycle Operations anim Device Bundle GPS Camera Telefon WLAN Menu Event Listener drawable-mdpi drawable-hdpi drawable Content View SD-Card • Was geschieht bei Events? • Nichts BlockierendesEmulator Short Operations onClick layout-land IDE Eclipse + ADT View layout Screen IntelliJ IDEA NetBeans (Telefon) • Warum bin ich so kurzlebig LAN AndroidManifest.xml maps.jar SDK Manager uses-sdk onCreate requires-feature uses-permission onStart platform-<n> docs Java JDK Herbstcampus 2012 – Roboter-Baukasten android.jar onResume SDK SD-Card sichtbar aktiv onPause tools onRestart adb AVD AVD Manager onStop onDestroy 18 Service Device Screen • Hintegrundoperationen Ressourcen Activity xml values values-en R ActionBar oder • Startbar von User anim menu bei Systemereignissen Dialog Sensoren GPS Lifecycle Operations Camera Bundle Telefon Service Menu Event Listener Content View drawable-mdpi drawable-hdpi drawable • Öffentliche Dienste Long Operations Short Operations WLAN SD-Card AIDL Emulator • AIDL • Aufrufbar von anderen Prozessen layout IDE Eclipse + ADT View layout-land IntelliJ IDEA NetBeans Screen (Telefon) LAN AndroidManifest.xml maps.jar SDK Manager uses-sdk requires-feature uses-permission platform-<n> docs android.jar SDK SD-Card adb tools AVD AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 19 Action App Laufzeitumgebung Activity Ressourcen Intent ActionBar anim values menu values-en tel: Telefon Intent.ACTION_VIEW http: Intent.ACTION_SENDTO mailto: Intent.ACTION_VIEW geo: Internet Screen Email Sensoren Map GPS Lifecycle Operations Camera Bundle Telefon Service Menu Content View Device Intent.ACTION_DIAL Event Listener drawable-mdpi drawable-hdpi drawable Startet Activity für Intent Dialog R xml Scheme Short Operations Long Operations WLAN SD-Card AIDL Emulator layout-land zum Start einer Activity oder Service • Nachricht Screen Adapter (Telefon) View Klasse • Dedizierte layout uses-sdk • Standard-Action und Uri AndroidManifest.xml requires-featureuses-permission • Objekt oder Content Ressource platform-<n> android.jar maps.jar WirdIntelliJ vonIDEA Laufzeitumgebung aufgelöst •IDE Eclipse NetBeans SDK Manager docs tools + ADT Action mit Extra-Daten • Custom SDK LAN SD-Card adb AVD AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 20 Laufzeitumgebung Device Screen Activity Ressourcen Broadcast Receiver Broadcast Receiver ActionBar anim menu values values-en Dialog R xml Sensoren GPS Lifecycle Operations Camera Bundle Telefon Service Menu Event Listener Content Erhalten Nachricht bei •drawable-mdpi Short Operations View drawable-hdpi drawable Systemereignissen Long Operations WLAN SD-Card AIDL Emulator layout-land Screen (Telefon) View • Boot completed layout • SMS received uses-sdk requires-feature AndroidManifest.xml uses-permission • WiFi connected platform-<n> android.jar maps.jar • Battery IntelliJ IDEAlow IDE Eclipse + ADT NetBeans SDK Manager • Können Services starten Herbstcampus 2012 – Roboter-Baukasten docs SDK tools LAN SD-Card adb AVD AVD Manager Java JDK 21 Laufzeitumgebung Device AlarmManager Ressourcen Widget menu R values-en Dialog Sensoren GPS Widget Camera Telefon Bundle WLAN Menu • Injizieren Content drawable-mdpi RemoteView View drawable-hdpi drawable in Oberfläche values onUpdate Lifecycle Operations anim xml Broadcast Receiver Activity ActionBar Screen Event Listener SD-Card Short Operations Emulator layout-land Screen View • Periodisch layout aktualisierbarAndroidManifest.xml IntelliJ IDEA IDE Broadcast • Eclipse NetBeans + ADT • Alarm maps.jar SDK Manager (Telefon) LAN uses-sdk requires-feature uses-permission platform-<n> docs android.jar SDK SD-Card adb tools AVD AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 22 Laufzeitumgebung android.R App Notifications Ressourcen menu values-en R values Dialog Widget Service Menu Content View Long Operations Short Operations Content ProviderListActivityContent • Bereitstellung von Daten Adapter View Uri IntelliJ IDEA maps.jar durch Projektionen • Auslesen NetBeans Eclipse + ADT GPS Camera AIDL CRUD Operations SD-Card Emulator Screen (Telefon) LAN AndroidManifest.xml Uri • Adressierung durch IDE Sensoren WLAN ContentProvider layout-land layout Screen Telefon Bundle Event Listener drawable-mdpi drawable-hdpi drawable SQLite Broadcast Receiver Lifecycle Operations anim xml AlarmManager Activity ActionBar Device SDK Manager uses-sdk requires-feature … SD-Card uses-permission com.android.bluetooth.opp.BluetoothOppProvider platform-<n> docs Java JDK Herbstcampus 2012 – Roboter-Baukasten com.android.browser.BrowserProvider com.android.htmlviewer.FileContentProvider android.jar adb AVD com.android.providers.applications.ApplicationsProvider com.android.providers.calendar.CalendarProvider2 com.android.providers.contacts.HtcContactsProvider2 com.android.providers.contacts.SocialProvider tools AVD Manager com.android.providers.downloads.DownloadProvider ... SDK 23 Laufzeitumgebung android.R App Notifications Ressourcen Activity ActionBar menu values-en Dialog R values AlarmManager IDE View ListActivity Eclipse + ADT NetBeans Camera Service Menu Short Operations Long Operations ListActivity IntelliJ IDEA GPS Telefon WLAN Uri SD-Card AIDL ContentProvider Adapter layout Sensoren Bundle Content View layout-land Screen Widget Event Listener drawable-mdpi drawable-hdpi drawable SQLite Broadcast Receiver Lifecycle Operations anim xml Device Emulator Screen (Telefon) CRUD Operations LAN uses-sdk Adapter verbindet requires-featureuses-permission •AndroidManifest.xml eines Teil-Layouts • Views platform-<n> android.jar maps.jar • Projektion eines Cursors SDK Manager docs SDK • Custom oder android.R SD-Card adb tools AVD AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 24 Laufzeitumgebung android.R App Notifications Ressourcen menu values-en R values Dialog IDE Eclipse + ADT NetBeans View Camera Service Menu Long Operations Short Operations ListActivity IntelliJ IDEA GPS Telefon WLAN Uri SD-Card AIDL ContentProvider Adapter layout Sensoren Bundle Content View layout-land Screen Widget Event Listener drawable-mdpi drawable-hdpi drawable SQLite Broadcast Receiver Lifecycle Operations anim xml AlarmManager Activity ActionBar Device Emulator Screen (Telefon) CRUD Operations LAN AndroidManifest.xml maps.jar SDK Manager uses-sdk requires-feature uses-permission platform-<n> docs android.jar SDK SD-Card adb tools AVD AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten 25 App android.R Laufzeitumgebung Launcher Ressourcen Notifications menu R values-en Dialog Event Listener drawable-mdpi drawable-hdpi drawable Content View ListActivity IDE Eclipse + ADT View IntelliJ IDEA GPS Widget Camera Long Operations WLAN SD-Card AIDL Emulator Content ContentProvider Uri Screen (Telefon) CRUD Operations LAN AndroidManifest.xml maps.jar uses-sdk requires-feature uses-permission platform-<n> SD-Card android.jar adb shell NetBeans Sensoren Intent Service Adapter layout Screen Telefon Short Operations onClick layout-land onUpdate Bundle onCreate Menu SQLite Broadcast Receiver Lifecycle Operations anim values AlarmManager Activity ActionBar xml Device SDK Manager docs SDK tools AVD logcat AVD Manager Java JDK Herbstcampus 2012 – Roboter-Baukasten WVGA800 26 Vielen Dank! Manfred Borzechowski LambdaLogic Informationssysteme GmbH