You are not alone on this phone

133
-1

Published on

This talk gives a brief overview of the options Android offers you to integrate with other apps.

Published in: Technology, Travel
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
133
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

You are not alone on this phone

  1. 1. DevFest Berlin 2013 You are not alone on this phone +Christian Ketterer / cketti
  2. 2. Christian Ketterer cketti ● 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 2
  3. 3. What's this all about? Android offers a lot of opportunities to integrate with other apps → use them! ● use functionality provided by other apps ● provide functionality other apps can use DevFest Berlin 2013 3
  4. 4. Application components ● Activities ● Services ● Content providers ● Broadcast receivers All application components can be used across app boundaries DevFest Berlin 2013 4
  5. 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 5
  6. 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 6
  7. 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 7
  8. 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 8
  9. 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 9
  10. 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 10
  11. 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 11
  12. 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 12
  13. 13. Structured data ● CRUD – – Retrieve (query) – Update – _id 1 2 Create (insert) Delete name keyboardsurfer cketti DevFest Berlin 2013 title Señor Developer Procrastinator extraordinaire 13
  14. 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 14
  15. 15. Examples ● Gmail (labels only) ● K-9 Mail ● Android – Contacts – Calendar – Call log – android.provider.* DevFest Berlin 2013 15
  16. 16. Broadcast receiver ● Receives Intents broadcasted via Context.sendBroadcast() ● Examples: – SMS received – Time changed – Boot complete – Connectivity change – Email received DevFest Berlin 2013 16
  17. 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 17
  18. 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 18
  19. 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 19
  20. 20. Take-away Make the Android experience more awesome by allowing other apps to integrate with yours DevFest Berlin 2013 20
  21. 21. Questions? DevFest Berlin 2013 21
  22. 22. Storage Access Framework DevFest Berlin 2013 22

×