22
DevFest Berlin 2013 You are not alone on this phone +Christian Ketterer / cketti

You are not alone on this phone

  • Upload
    cketti

  • View
    112

  • Download
    3

Embed Size (px)

Citation preview

Page 1: You are not alone on this phone

DevFest Berlin 2013

You are not alone on this phone

+Christian Ketterer / cketti

Page 2: You are not alone on this phone

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

Page 3: You are not alone on this phone

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!

Page 4: You are not alone on this phone

DevFest Berlin 2013 4

Application components

All application components can be used across app boundaries

● Activities● Services● Content providers● Broadcast receivers

Page 5: You are not alone on this phone

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)

Page 6: You are not alone on this phone

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)

Page 7: You are not alone on this phone

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>

Page 8: You are not alone on this phone

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

Page 9: You are not alone on this phone

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);}

Page 10: You are not alone on this phone

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.

Page 11: You are not alone on this phone

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

Page 12: You are not alone on this phone

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

Page 13: You are not alone on this phone

DevFest Berlin 2013 13

Structured data

● CRUD– Create (insert)

– Retrieve (query)

– Update

– Delete

_id name title1 keyboardsurfer Señor Developer2 cketti Procrastinator extraordinaire

Page 14: You are not alone on this phone

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, …)

Page 16: You are not alone on this phone

DevFest Berlin 2013 16

Broadcast receiver

● Receives Intents broadcasted via Context.sendBroadcast()

● Examples:– SMS received

– Time changed

– Boot complete

– Connectivity change

– Email received

Page 17: You are not alone on this phone

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>

Page 18: You are not alone on this phone

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*

Page 19: You are not alone on this phone

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

Page 20: You are not alone on this phone

DevFest Berlin 2013 20

Take-away

Make the Android experience more awesome by allowing other apps to integrate with

yours

Page 21: You are not alone on this phone

DevFest Berlin 2013 21

Questions?

Page 22: You are not alone on this phone

DevFest Berlin 2013 22

Storage Access Framework