Upload
cketti
View
112
Download
3
Tags:
Embed Size (px)
Citation preview
DevFest Berlin 2013
You are not alone on this phone
+Christian Ketterer / cketti
DevFest Berlin 2013 2
Christian Ketterercketti
● Freelancer, Android!● K-9 Mail core contributor ● Open source enthusiast● Co-Organizer:
– Android Stammtisch Berlin
– Google I/O Extended Berlin
– DevFest Berlin
DevFest Berlin 2013 3
What's this all about?
● use functionality provided by other apps● provide functionality other apps can use
Android offers a lot of opportunities to integrate with other apps → use them!
DevFest Berlin 2013 4
Application components
All application components can be used across app boundaries
● Activities● Services● Content providers● Broadcast receivers
DevFest Berlin 2013 5
What are Intents again?
● „An intent is an abstract description of an operation to be performed.“
→ stores data that is interpreted by others● Contains:
– Action
– Data (URI)
– Type
– Extras („simple“ data types)
DevFest Berlin 2013 6
Activity
● „An activity is a single, focused thing that the user can do.“
● You can start activities of other apps– startActivity(Intent)– startActivityForResult(Intent, int)
DevFest Berlin 2013 7
Expose your activity
<activity android:name=".ShareActivity"> <intent-filter> <action android:name="android.intent.action.SEND"/> <category android:name="android.intent.category.DEFAULT"/> <data android:mimeType="text/plain"/> <data android:mimeType="image/*"/> </intent-filter></activity>
<activity android:name=".InterestingActivity" android:label="Do something" android:exported="true"></activity>
DevFest Berlin 2013 8
Service
● „A Service is an application component that can perform long-running operations in the background and does not provide a user interface.“
● Can be used for interprocess communication (IPC) → Context.bindService()
● Allows you to call exposed methods in another app
DevFest Berlin 2013 9
AIDL
package com.example.aidl;
interface IRemoteService { int giveMeAnInt();
void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString);
oneway void setCallback(in ICallback callback);}
DevFest Berlin 2013 10
Examples
● DashClock Widget (extensions)● OpenPGP Keychain● OpenIntents Safe
If you know of any other (open source) app making use of this functionality, please let me know.
DevFest Berlin 2013 11
Content provider
● „Content providers are the standard interface that connects data in one process with code running in another process.“
● Exposes structured set of data (think: table in an SQL database)
● Read and write data blobs● Notification mechanism when data has
changed
DevFest Berlin 2013 12
Give me your content://
● ContentResolver is used to access a content provider
● Needs a content:// URI– Authority: specifies which content provider to use
– Path: specifies what data to access
● Example:content://com.fsck.k9.messageprovider/inbox_messages
DevFest Berlin 2013 13
Structured data
● CRUD– Create (insert)
– Retrieve (query)
– Update
– Delete
_id name title1 keyboardsurfer Señor Developer2 cketti Procrastinator extraordinaire
DevFest Berlin 2013 14
Notification mechanism
● Be notified when data managed by the content provider changes:
ContentResolver.registerContentObserver()
● Notify when data was changed:
ContentResolver.notifyChange(Uri, …)
DevFest Berlin 2013 15
Examples
● Gmail (labels only)● K-9 Mail● Android
– Contacts
– Calendar
– Call log– android.provider.*
DevFest Berlin 2013 16
Broadcast receiver
● Receives Intents broadcasted via Context.sendBroadcast()
● Examples:– SMS received
– Time changed
– Boot complete
– Connectivity change
– Email received
DevFest Berlin 2013 17
Finding components to talk to
● Use PackageManager.queryIntent*()● <intent-filter>
● <meta-data>
<service android:name=".FancyService"> <intent-filter>…</intent-filter>
<meta-data android:name="protocolVersion" android:value="1"/>
<meta-data android:name="settingsActivity" android:value="com.example.app.SettingsActivity"/></service>
DevFest Berlin 2013 18
Important
● Protect components exposing sensitive data using Android permissions
● It's a public API!– Use versioning
– If you make a mistake not only your app will break
● Make sure you read the official documentation when adding support for standard intent actions*
DevFest Berlin 2013 19
Summary
● Expose an Activity to provide some functionality requiring an user interface
● Use a Service to allow performing (background) actions
● Allow others to read/write your data using a content provider
● Send broadcast intents to notify others of important events
DevFest Berlin 2013 20
Take-away
Make the Android experience more awesome by allowing other apps to integrate with
yours
DevFest Berlin 2013 21
Questions?
DevFest Berlin 2013 22
Storage Access Framework