Android - jsug.at · Android And Me Why I like Android Blend of Linux and Java Open (Source)...
Transcript of Android - jsug.at · Android And Me Why I like Android Blend of Linux and Java Open (Source)...
Android
Michael Greifeneder
Image source: Android homepage
Inhalt
● Overwiew● Hardware● Software
● Development● Tools● Basics● Debugging/Emulator● Location
● Demo
Android And Me
● Why I like Android● Blend of Linux and Java● Open (Source)● Development on Ubuntu :)● USB mass storage● Tethering (USB, Wifi)
● Don't like● Battery life● Default LookNFeel
Hardware
● Typically ARM processors, up to 1 GHz● 256-512 MB RAM, up to 1 GB ROM● Connectivity: GSM/EDGE, UMTS,
Bluetooth, Wi-Fi, and WiMAX.● Cameras, GPS, accelerometers, SD card● Optional
physical keyboard● ~34 devices...
Image sources: Device manufacturer
3,4
28
13,8
12,3
4,73,1
Forecast 2010 North America
SymbianRIMAppleGoogleMicrosoftPalm
44,3
19,4
15,4
9,6
6,83,70,7
1Q10 Worldwide Sales
SymbianResearch In MotioniPhone OSAndroidMicrosoft Windows MobileLinuxOther OSs
Smartphone Sales Stats● North America
● Source: Canalys● Total: 65 Mio
● Worldwide 1Q10● Source: Gartner● Total: 54 Mio/Q
http://www.gartner.com/it/page.jsp?id=1372013 http://www.gartner.com/it/page.jsp?id=985912
2008 2009 2010
0
2
4
6
8
10
12
14
16
18
Q1 Worldwide
AndroidiPhone
Markets● Google's Android Market (>50.000 Apps)
● 25$ one-time registration● No restrictions
● Alternatives available (android.pdassi.de)● Just click on an .apk file...
http://xkcd.com/662/ Creative Commons Attribution-NonCommercial 2.5 License.
Software● Tweaked Linux kernel (2.6.27-32)
● No X Window System● Dalvik/Java Runtime
● register-based architecture● .dex format● dx tool convert .class files to .dex● Neither AWT, Swing nor JavaME
supported● JIT implementation (Android 2.2)
● Open Source (Apache license)
Architecturehttp://developer.android.com/guide/basics/what-is-android.html
Kernelhttp://android.git.kernel.org/
From Kevin Mcdonagh slides: http://www.scribd.com/doc/31664622/Android-Source-Code-Guided-Tour
Versions
● Cupcake● 1.5 (API 3)
● Donut● 1.6 (API 4)
● Eclair● 2.0 (API 5), 2.0.1 (API 6) +2.1 (API 7)
● FroYo (Frozen Yoghurt)● 2.2 (API 8)
Image source: Android homepage
Development
● Android SDK● → http://developer.android.com/sdk
● Eclipse + Android Development Tools● https://dl-ssl.google.com/android/eclipse/
● Java+XML● C/C++ for NDK
Image source: Self-made screenshots
Toolset
● adb (Android Debug Bridge)● Installing an Application● Copying Files to or from Device/Emulator● Remote Shell
● z.B. Sqlite command-line
● DDMS (Dalvik Debug Monitor Server)● Uses adb● middleman btw. IDE + applications
● logcat
Emulator
● Android Virtual Devices (AVD)● hardware profile● mapping to a system image● dedicated storage area
● Emulator runs AVDs● Emulates: Calls, SMS● Location, Camera● Network-speed
Image source: Self-made screenshots
Widgets● Layout in XML files● Layouts: LinearLayout,
RelativeLayout, FrameLayout, TableLayout,AbsoluteLayout(pfui)
● Basic Widgets: TextView, Button, EditText, ImageView
● DatePicker, TimePicker, Tabs● OptionMenu, ContextMenu● WebView (WebKit)
Image source: Self-made screenshots
GUI Designer?
● Android Layout Editor in Eclipse● Forget it.
● DroidDraw http://www.droiddraw.org/● Yeah,
but...
Image source: Self-made screenshots
Project Structure
● AndroidManifest.xml● /src● /res
● /layout● /menu● /drawable
● /gen● /values/strings.xml
Security
● User must confirm access● Declare required
permissions inAndroidManifest.xml
● <uses-permission android:name= "android.permission.INTERNET"/>
● <uses-permission android:name= "android.permission. ACCESS_FINE_LOCATION" />
● <uses-permission android:name= "android.permission.CAMERA" />
Image source: http://www.taosoftware.co.jp/en/android/wakeupcallmaker/
Activities <--> Intents
● Activity = One screen● Intents (abstract description of an operation)
● Explicit intents (same app)● Implicit intents (inter App operation)
● Example:● Action: Intent.ACTION_DIAL● Data: ”tel:01567890”
● Intent filters● Declare receiving of intents
Activity
● Methods● onCreate
● setContentView(R.layout.XML_FILE);● findViewById(R.id.ID_IN_LAYOUT);
● onDestroy/onPause/onResume● Call internal activity
● Intent intent = new Intent(this, OtherActivity.class);startActivity(intent); //or startActivityForResult(intent, 1);
The Mighty List
● android.widget.ListView(ListActivity)
● ListAdapter for data● Indiviual layout for row● ArrayAdapter
one Textview in row● SimpleCursorAdapter
● Maps DB columns to resource ids in row layout
Image source: Self-made screenshots
Services...
● Use case● Background tasks● Long running tasks
● Implement a service● AndroidManiferst.xml
<service android:name=".MyService" />
● onCreate/onStart/onDestroy
● onBind() → return a subclassed Binder that extends Binder and implements custom method:
getService()
Use Service (local)
● Intent intent = new Intent(this. Service.class)
● bindService(intent, serviceConnection, 0);
● interface ServiceConnection {onServiceConnected(Binder binder,...)onServiceDisconnected(...)}
● ((LocalBinder) binder).getService()
Location aware
● LocationManager● getLastKnownLocation● Register for periodic updates● Get notified on location
● Emulator● Open console● telnet localhost <5554?>● geo fix <longitude> <latitude>
Demos
● DB query● Location (Change location in emulator)● Camera
● Intent: android.media.action.IMAGE_CAPTURE is buggy
● http://code.google.com/p/android/issues/detail?id=1480
● Workaround: Do it yourself● Internet
● <uses-permission android:name="android.permission.INTERNET"/>
Source code:http://github.com/mikegr/aLogMyNight
eBooks:http://commonsware.com/books
??? Questions/Discussion ???