Android-Entwicklung. Michael secure Stapelberg



Similar documents
Android Introduction. Hello Mihail L. Sichitiu 1

Android For Java Developers. Marko Gargenta Marakana

Mobile Application Development

Saindo da zona de conforto resolvi aprender Android! by Daniel Baccin

Android Services. Services

Chapter 2 Getting Started

Università Degli Studi di Parma. Distributed Systems Group. Android Development. Lecture 2 Android Platform. Marco Picone

Android Development. Marc Mc Loughlin

Basics. Bruce Crawford Global Solutions Manager

4. The Android System

MMI 2: Mobile Human- Computer Interaction Android

Introduction to Android SDK Jordi Linares

TUTORIALS AND QUIZ ANDROID APPLICATION SANDEEP REDDY PAKKER. B. Tech in Aurora's Engineering College, 2013 A REPORT

directory to "d:\myproject\android". Hereafter, I shall denote the android installed directory as

ANDROID AS A PLATFORM FOR DATABASE APPLICATION DEVELOPMENT

Building an Android client. Rohit Nayak Talentica Software

Android 多 核 心 嵌 入 式 多 媒 體 系 統 設 計 與 實 作

Now that we have the Android SDK, Eclipse and Phones all ready to go we can jump into actual Android development.

Developing Android Apps: Part 1

Tutorial #1. Android Application Development Advanced Hello World App

Admin. Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources. Recap: TinyOS. Recap: J2ME Framework

Based on Android 4.0. by Lars Vogel. Version 9.8. Copyright 2009, 2010, 2011, 2012 Lars Vogel Home Tutorials Trainings Books Social

Creating a List UI with Android. Michele Schimd

App Development for Android. Prabhaker Matet

MAP524/DPS924 MOBILE APP DEVELOPMENT (ANDROID) MIDTERM TEST OCTOBER 2013 STUDENT NAME STUDENT NUMBER

Getting Started With Android

Android Persistency: Files

Android Application Development. Daniel Switkin Senior Software Engineer, Google Inc.

BEGIN ANDROID JOURNEY IN HOURS

Android Apps Development Boot Camp. Ming Chow Lecturer, Tufts University DAC 2011 Monday, June 6, 2011

Developing apps for Android OS: Develop an app for interfacing Arduino with Android OS for home automation

SDK Quick Start Guide

getsharedpreferences() - Use this if you need multiple preferences files identified by name, which you specify with the first parameter.

Android Bootcamp. Elaborado (com adaptações) a partir dos tutoriais:

Developing an Android App. CSC207 Fall 2014

Getting started with Android and App Engine

Android Development Tutorial

Android Services. Android. Victor Matos

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

Smartphone market share

Android Concepts and Programming TUTORIAL 1

Android Basics. Xin Yang

Hacking your Droid ADITYA GUPTA

How to develop your own app

Tutorial: Setup for Android Development

ADITION Android Ad SDK Integration Guide for App Developers

Android Programming. Android App. Høgskolen i Telemark Telemark University College. Cuong Nguyen,

Android Development Tutorial. Human-Computer Interaction II (COMP 4020) Winter 2013

Android App Development. Rameel Sethi

AdFalcon Android SDK Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group

Localization and Resources

A software stack for mobile devices:

Android Application Development: Hands- On. Dr. Jogesh K. Muppala

2. Installieren des MySQL Workbench (Version ) 3. Unter Database > Manage Connection folgende Werte eintragen

Developing Android Applications: Case Study of Course Design

Woubshet Behutiye ANDROID ECG APPLICATION DEVELOPMENT

Location-Based Services Design and Implementation Using Android Platforms

Presenting Android Development in the CS Curriculum

ODROID Multithreading in Android

Android Programming Basics

UNIVERSITY AUTHORISED EDUCATION PARTNER (WDP)

Android Programming. An Introduction. The Android Community and David Read. For the CDJDN April 21, 2011

Building Your First App

Android Application Development. Yevheniy Dzezhyts

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

Beginning Android Programming

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Q1. What method you should override to use Android menu system?

ITG Software Engineering

PubMatic Android SDK. Developer Guide. For Android SDK Version 4.3.5

Report and Opinion 2014;6(7) Technical Specification for Creating Apps in Android. Kauser Hameed, Manal Elobaid

Android Application Development Lecture Notes INDEX

Learning Android Marko Gargenta

Google Android Syllabus

INTRODUCTION TO ANDROID CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 11 02/15/2011

Android Application Development

Android Certified Application Developer AND-401

Tutorial: Android Object API Application Development. SAP Mobile Platform 2.3

ELET4133: Embedded Systems. Topic 15 Sensors

Here to take you beyond Mobile Application development using Android Course details

Tutorial: Android Object API Application Development. Sybase Unwired Platform 2.2 SP02

ANDROID TUTORIAL. Simply Easy Learning by tutorialspoint.com. tutorialspoint.com

Introduction to Android: Hello, Android! 26 Mar 2010 CMPT166 Dr. Sean Ho Trinity Western University

Getting Started: Creating a Simple App

CSE476 Mobile Application Development. Yard. Doç. Dr. Tacha Serif Department of Computer Engineering Yeditepe University

Transcription:

Android-Entwicklung Michael secure Stapelberg

Folien Disclaimer

Überblick 1 Die Android-Plattform 2 Entwicklungsumgebung 3 4 Grundlagen Layout, Activity, Manifest, Listener, Intents Framework Adapter, Datenhaltung, Netzzugriff, Concurrency, GeoLocation

Die Android-Plattform

Android Linux-basiert. Smartphones, Tablets, Netbooks, Java

Verbreitung

Versionen

Android-Überblick Anwendungen: Adressbuch, Browser, Framework: Location Manager, Activity Manager, Libraries: SQLite, libc, Runtime: Dalvik, Core Libraries Linux Kernel: Treiber

jetzt klar: Wichtigste Aspekte der Android-Plattform

2 Entwicklungsumgebung

Entwicklungsumgebung Eclipse! ADB (Android Debug Bridge) Emulator

2 jetzt klar: Entwicklungsumgebung

Grundlagen

Activities eine Bildschirm-Ansicht für einen Zweck (z.b. E-Mail anzeigen, E-Mail schreiben, ) genau eine zugehörige Klasse fremde Activities

Lifecycle einer Activity

Layouts Android-Eigenentwicklung XML-Dateien in res/layouts/ als Activity oder Teil (z.b. Liste) Views oder ViewGroups Button TextView ImageView EditText LinearLayout RelativeLayout

Helloworld

Helloworld (XML) <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:id="@+id/hellotext" /> </LinearLayout>

Views (Beispiele) Siehe Resources Tutorials Hello Views

Listener final TextView text = (TextView)findViewById(R.id.ohai); text.setonclicklistener(new OnClickListener() { @Override public void onclick(view v) { Log.d("MeineApp", "Geklickt."); text.settext("kthxbye"); } });

Activity package org.rzl.hello; import /*... */; public class main extends Activity { @Override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); } } /* Listener einrichten */

Intents GoodbyeWorld HelloWorld Intent System Music Gallery Browser

Intents (Third-Party) String url = "http://raumzeitlabor.de/"; Intent i = new Intent(Intent.ACTION_VIEW); i.setdata(uri.parse(url)); startactivity(i);

Intents (App) Intent i = new Intent(this, GoodbyeWorld.class); startactivity(i);

Manifest Metadaten der App enthaltene Activities Permissions

Manifest (XML)?xml version="1.0" encoding="utf-8"?> manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.rzl.hello" android:versioncode="1" android:versionname="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".main" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".goodbyeworld" android:label="bye!" /> </application> <uses-sdk android:minsdkversion="4" /> <uses-permission android:name="android.permission.internet" /> /manifest>

jetzt klar: Grundlagen

Framework

Adapter ListView fragt Adapter nach Daten ArrayAdapter für Listen (ggf. überladen) vorhandene Views neu befüllen

ArrayAdapter setlistadapter(new MessagesAdapter(db.getMessages())); class MessagesAdapter extends ArrayAdapter<String> { MessagesAdapter(ArrayList<String> entries) { super(messages.this, R.layout.messages_item, entries); } @Override public View getview(int position, View row, ViewGroup parent) { TextView text; if (row == null) { LayoutInflater inflater = getlayoutinflater(); row = inflater.inflate(r.layout.message, parent, false); } } text = (TextView)row.findViewById(R.id.message_text); row.settag(r.id.message_text, text); } else text = (TextView)row.getTag(R.id.message_text); text.settext(getitem(position)); return row;

Datenhaltung Dateien SharedPreferences SQLite alles nur von der App lesbar

SharedPreferences Datentypen: int, string, boolean, float, long schreibt in XML-Datei Bonus: PreferenceActivity

SharedPreferences SharedPreferences settings = getsharedpreferences(prefs_name, 0); boolean silent = settings.getboolean("silentmode", false); SharedPreferences.Editor editor = settings.edit(); editor.putboolean("silentmode", msilentmode); /* Commit, unbedingt aufrufen! */ editor.commit();

SQLite Datenbank, SQL-Schnittstelle bester Weg für viele Daten embedded; kein volles DBMS

SQLite (öffnen) public class DBHelper extends SQLiteOpenHelper { DBHelper(Context context) { super(context, "rzldb", null, 1); } } @Override public void oncreate(sqlitedatabase db) { db.execsql("create TABLE foo (bar INTEGER)"); }

SQLite (schreiben) SQLiteDatabase db = helper.getwritabledatabase(); SQLiteStatement stmt = db.compilestatement( "INSERT INTO TABLE foo (bar) VALUES (?)"); stmt.bindlong(1, 23425); stmt.execute();

SQLite (lesen) int result; SQLiteDatabase db = helper.getreadabledatabase(); Cursor c = db.rawquery("select * FROM foo", NULL); if (c.movetofirst()) result = c.getint(0); if (c!= null &&!c.isclosed()) { c.close(); } /* result benutzen */

SimpleCursorAdapter Cursor c = db.getmessages(); startmanagingcursor(c); SimpleCursorAdapter adapter = new SimpleCursorAdapter( this, R.layout.messages_item, c, new String[] { "Text" }, new int[] { R.id.message_text }); setlistadapter(adapter);

Netzzugriff HTTP + JSON AndroidHttpClient (HttpClient) in separatem Thread! ( AsyncTask)

Netzzugriff InputStream uploadvalue(string Messwert) throws Exception { HttpPost req = new HttpPost("http://mein.server/foo"); req.setentity(new ByteArrayEntity(Messwert.getBytes())); req.addheader("accept-encoding", "gzip"); } AndroidHttpClient client = AndroidHttpClient.newInstance(""); HttpResponse response = client.execute(req); StatusLine statusline = response.getstatusline(); if (statusline.getstatuscode()!= 200) { Log.e("MyApp", "HTTP Error: " + statusline.tostring()); throw new Exception("HTTP Error"); } HttpEntity e = response.getentity(); InputStream s = AndroidHttpClient.getUngzippedContent(e); return new BufferedReader(new InputStreamReader(s), 8192).readLine();

AsyncTask class CreateUserTask extends AsyncTask<String, Void, String> { private ProgressDialog dialog; @Override protected void onpreexecute() { dialog = new ProgressDialog(main.this); dialog.settitle("downloading the internet"); dialog.show(); } @Override protected String doinbackground(string... params) { uploadvalue("fnord"); return null; } @Override protected void onpostexecute(string errormessage) { dialog.dismiss(); } }

Geolocation GPS, Triangulation, WLAN Manifest: ACCESS_COARSE_LOCATION (Netz) oder ACCESS_FINE_LOCATION (GPS) Koordinaten selbst beurteilen möglichst kurz Location anfordern

GeoLocation verfügbar? String provider = Settings.Secure.getString( getcontentresolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); if (provider!= null &&!provider.equals("")) { Log.v("MyApp", "Location providers: " + provider); } else { Log.e("MyApp", "No location providers"); startactivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); }

GeoLocation abonnieren lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); lm.requestlocationupdates(locationmanager.gps_provider, 5 * 1000, 0, newloc); lm.requestlocationupdates(locationmanager.network_provider, 5 * 1000, 0, newloc); private LocationListener newloc = new LocationListener() { public void onlocationchanged(location location) { Log.d("MyApp", "newlocation: lat " + location.getlatitude() + ", lon " + location.getlongitude()); } }; Dev Guide Location and Maps Obtaining User Location

Fertig! Danke! http://d.android.com/ http://www.stackoverflow.com/ [android] foo google android foo