SlideShare a Scribd company logo
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents 1
1
Activities and
Intents
1
Android Developer Fundamentals V2
Lesson 2
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
2.3 Implicit Intents
2
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Contents
● Intent—recap
● Implicit Intent overview
● Sending an implicit Intent
● Receiving an implicit Intent
3
Android Developer Fundamentals V2
Recap: Intent
4
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
What is an Intent?
5
An Intent is:
● Description of an operation to be performed
● Messaging object used to request an action from another
app component via the Android system.
App component
Originator
Intent Action
Android
System
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
What can an Intent do?
An Intent can be used to:
● start an Activity
● start a Service
● deliver a Broadcast
Services and Broadcasts are covered in other lessons
6
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Explicit vs. implicit Intent
7
Explicit Intent — Starts an Activity of a specific class
Implicit Intent — Asks system to find an Activity class with a
registered handler that can handle this request
Android Developer Fundamentals V2
Implicit Intent
overview
8
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
What you do with an implicit Intent
● Start an Activity in another app by describing an action you
intend to perform, such as "share an article", "view a map",
or "take a picture"
● Specify an action and optionally provide data with which to
perform the action
● Don't specify the target Activity class, just the intended
action
9
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
What system does with implicit Intent
10
● Android runtime matches the implicit intent request with
registered intent handlers
● If there are multiple matches, an App Chooser will open to
let the user decide
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
How does implicit Intent work?
11
1. The Android Runtime keeps a list of registered Apps
2. Apps have to register via AndroidManifest.xml
3. Runtime receives the request and looks for matches
4. Android runtime uses Intent filters for matching
5. If more than one match, shows a list of possible matches
and lets the user choose one
6. Android runtime starts the requested activity
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
App Chooser
12
When the Android runtime finds
multiple registered activities that can
handle an implicit Intent, it displays an
App Chooser to allow the user to select
the handler
Android Developer Fundamentals V2
Sending an
implicit Intent
13
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Sending an implicit Intent
14
1. Create an Intent for an action
Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);
User has pressed Call button — start Activity that can make
a call (no data is passed in or returned)
1. Start the Activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Avoid exceptions and crashes
15
Before starting an implicit Activity, use the package manager
to check that there is a package with an Activity that matches
the given criteria.
Intent myIntent = new Intent(Intent.ACTION_CALL_BUTTON);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Sending an implicit Intent with data URI
16
1. Create an Intent for action
Intent intent = new Intent(Intent.ACTION_DIAL);
1. Provide data as a URI
intent.setData(Uri.parse("tel:8005551234"));
1. Start the Activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Providing the data as URI
17
Create an URI from a string using Uri.parse(String uri)
● Uri.parse("tel:8005551234")
● Uri.parse("geo:0,0?q=brooklyn%20bridge%2C%20brooklyn%2C%20ny")
● Uri.parse("http://www.android.com");
Uri documentation
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Implicit Intent examples
18
Show a web page
Uri uri = Uri.parse("http://www.google.com");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
Dial a phone number
Uri uri = Uri.parse("tel:8005551234");
Intent it = new Intent(Intent.ACTION_DIAL, uri);
startActivity(it);
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Sending an implicit Intent with extras
19
1. Create an Intent for an action
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
1. Put extras
String query = edittext.getText().toString();
intent.putExtra(SearchManager.QUERY, query));
1. Start the Activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Category
20
Additional information about the kind of component to
handle the intent.
● CATEGORY_OPENABLE
Only allow URIs of files that are openable
● CATEGORY_BROWSABLE
Only an Activity that can start a web browser to display
data referenced by the URI
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Sending an implicit Intent with type and category
21
1. Create an Intent for an action
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
1. Set mime type and category for additional information
intent.setType("application/pdf"); // set MIME type
intent.addCategory(Intent.CATEGORY_OPENABLE);
continued on next slide...
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Sending an implicit Intent with type and category
22
3. Start the Activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(myIntent,ACTIVITY_REQUEST_CREATE_FILE);
}
4. Process returned content URI in onActivityResult()
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Common actions for an implicit Intent
23
Common actions include:
● ACTION_SET_ALARM
● ACTION_IMAGE_CAPTURE
● ACTION_CREATE_DOCUMENT
● ACTION_SENDTO
● and many more
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Apps that handle common actions
24
Common actions are usually handled by installed apps (both
system apps and other apps), such as:
● Alarm Clock, Calendar, Camera, Contacts
● Email, File Storage, Maps, Music/Video
● Notes, Phone, Search, Settings
● Text Messaging and Web Browsing
➔ List of common
actions for an
implicit intent
➔ List of all
available actions
Android Developer Fundamentals V2
Receiving an
Implicit Intent
25
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Register your app to receive an Intent
26
● Declare one or more Intent filters for the Activity in
AndroidManifest.xml
● Filter announces ability of Activity to accept an implicit
Intent
● Filter puts conditions on the Intent that the Activity accepts
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Intent filter in AndroidManifest.xml
27
<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"/>
</intent-filter>
</activity>
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Intent filters: action and category
28
● action — Match one or more action constants
○ android.intent.action.VIEW — matches any Intent with ACTION_VIEW
○ android.intent.action.SEND — matches any Intent with ACTION_SEND
● category — additional information (list of categories)
○ android.intent.category.BROWSABLE—can be started by web browser
○ android.intent.category.LAUNCHER—Show activity as launcher icon
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Intent filters: data
29
● data — Filter on data URIs, MIME type
○ android:scheme="https"—require URIs to be https protocol
○ android:host="developer.android.com"—only accept an Intent from
specified hosts
○ android:mimeType="text/plain"—limit the acceptable types of documents
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents 30
An Activity can have multiple filters
<activity android:name="ShareActivity">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
...
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE"/>
...
</intent-filter>
</activity> An Activity can have several filters
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
A filter can have multiple actions & data
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<action android:name="android.intent.action.SEND_MULTIPLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="image/*"/>
<data android:mimeType="video/*"/>
</intent-filter>
31
Android Developer Fundamentals V2
Learn more
32
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
Learn more
● Intent class documentation
● Uri documentation
● List of common apps that respond to implicit intents
● List of available actions
● List of categories
● Intent Filters
33
Android Developer Fundamentals V2
This work is licensed under a Creative
Commons Attribution 4.0 International
License.
Implicit Intents
What's Next?
34
● Concept Chapter: 2.3 Implicit Intents
● Practical: 2.3 Implicit Intents
Android Developer Fundamentals V2
END
35

More Related Content

PPTX
2.1-Activities and Intents.pptx
ab2478037
 
PPTX
Tk2323 lecture 3 intent
MengChun Lam
 
PPTX
Week 7
AinaMarini
 
PDF
Intents in Android
ma-polimi
 
PDF
2.1 Activities and Intents.pdf
SiaTeknokrat
 
DOCX
Android intents in android application-chapter7
Dr. Ramkumar Lakshminarayanan
 
PPTX
Intents in Mobile Application Development.pptx
AbinayaDeviC
 
DOCX
Using intents in android
Oum Saokosal
 
2.1-Activities and Intents.pptx
ab2478037
 
Tk2323 lecture 3 intent
MengChun Lam
 
Week 7
AinaMarini
 
Intents in Android
ma-polimi
 
2.1 Activities and Intents.pdf
SiaTeknokrat
 
Android intents in android application-chapter7
Dr. Ramkumar Lakshminarayanan
 
Intents in Mobile Application Development.pptx
AbinayaDeviC
 
Using intents in android
Oum Saokosal
 

Similar to 3-Implicit Intents.pptx (20)

PPT
Android - Android Intent Types
Vibrant Technologies & Computers
 
PPTX
MAD_Intentuffjgfjjjhgjjgjjggjghggghggh.pptx
himanshunanobhatt
 
PPTX
Android - Intents and Filters hgfh gfh.pptx
FarhanGhafoor7
 
PPT
Intent.ppt
DharmendraSingh655367
 
PDF
Intents are Awesome
Israel Camacho
 
PPTX
W5_Lec09_Lec10_Intents.pptx
ChSalmanSalman
 
PDF
Android App Development 07 : Intent &amp; Share
Anuchit Chalothorn
 
PDF
Ch5 intent broadcast receivers adapters and internet
Shih-Hsiang Lin
 
PPTX
learn about Android Extended Intents.pptx
adgeofspace04
 
PPT
Android Bootcamp Tanzania:intents
Denis Minja
 
PPT
Intent, Service and BroadcastReciver (2).ppt
BirukMarkos
 
PPTX
Android - Intents - Mazenet Solution
Mazenetsolution
 
PDF
Tut123456.pdf
marhabaopera
 
PPTX
Android Intent.pptx
vishal choudhary
 
PDF
Android intent
Krazy Koder
 
PDF
Android Basics
Arvind Sahu
 
PPT
ANDROID
DrMeftahZouai
 
PDF
Android intents
Siva Ramakrishna kv
 
ODP
Ppt 2 android_basics
Headerlabs Infotech Pvt. Ltd.
 
PPTX
Android Mobile App Development basics PPT
nithya697634
 
Android - Android Intent Types
Vibrant Technologies & Computers
 
MAD_Intentuffjgfjjjhgjjgjjggjghggghggh.pptx
himanshunanobhatt
 
Android - Intents and Filters hgfh gfh.pptx
FarhanGhafoor7
 
Intents are Awesome
Israel Camacho
 
W5_Lec09_Lec10_Intents.pptx
ChSalmanSalman
 
Android App Development 07 : Intent &amp; Share
Anuchit Chalothorn
 
Ch5 intent broadcast receivers adapters and internet
Shih-Hsiang Lin
 
learn about Android Extended Intents.pptx
adgeofspace04
 
Android Bootcamp Tanzania:intents
Denis Minja
 
Intent, Service and BroadcastReciver (2).ppt
BirukMarkos
 
Android - Intents - Mazenet Solution
Mazenetsolution
 
Tut123456.pdf
marhabaopera
 
Android Intent.pptx
vishal choudhary
 
Android intent
Krazy Koder
 
Android Basics
Arvind Sahu
 
ANDROID
DrMeftahZouai
 
Android intents
Siva Ramakrishna kv
 
Ppt 2 android_basics
Headerlabs Infotech Pvt. Ltd.
 
Android Mobile App Development basics PPT
nithya697634
 
Ad

Recently uploaded (20)

DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
How to Apply for a Job From Odoo 18 Website
Celine George
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Basics and rules of probability with real-life uses
ravatkaran694
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
How to Apply for a Job From Odoo 18 Website
Celine George
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Ad

3-Implicit Intents.pptx

  • 1. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents 1 1 Activities and Intents 1 Android Developer Fundamentals V2 Lesson 2
  • 2. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents 2.3 Implicit Intents 2
  • 3. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Contents ● Intent—recap ● Implicit Intent overview ● Sending an implicit Intent ● Receiving an implicit Intent 3
  • 4. Android Developer Fundamentals V2 Recap: Intent 4
  • 5. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents What is an Intent? 5 An Intent is: ● Description of an operation to be performed ● Messaging object used to request an action from another app component via the Android system. App component Originator Intent Action Android System
  • 6. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents What can an Intent do? An Intent can be used to: ● start an Activity ● start a Service ● deliver a Broadcast Services and Broadcasts are covered in other lessons 6
  • 7. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Explicit vs. implicit Intent 7 Explicit Intent — Starts an Activity of a specific class Implicit Intent — Asks system to find an Activity class with a registered handler that can handle this request
  • 8. Android Developer Fundamentals V2 Implicit Intent overview 8
  • 9. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents What you do with an implicit Intent ● Start an Activity in another app by describing an action you intend to perform, such as "share an article", "view a map", or "take a picture" ● Specify an action and optionally provide data with which to perform the action ● Don't specify the target Activity class, just the intended action 9
  • 10. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents What system does with implicit Intent 10 ● Android runtime matches the implicit intent request with registered intent handlers ● If there are multiple matches, an App Chooser will open to let the user decide
  • 11. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents How does implicit Intent work? 11 1. The Android Runtime keeps a list of registered Apps 2. Apps have to register via AndroidManifest.xml 3. Runtime receives the request and looks for matches 4. Android runtime uses Intent filters for matching 5. If more than one match, shows a list of possible matches and lets the user choose one 6. Android runtime starts the requested activity
  • 12. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents App Chooser 12 When the Android runtime finds multiple registered activities that can handle an implicit Intent, it displays an App Chooser to allow the user to select the handler
  • 13. Android Developer Fundamentals V2 Sending an implicit Intent 13
  • 14. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Sending an implicit Intent 14 1. Create an Intent for an action Intent intent = new Intent(Intent.ACTION_CALL_BUTTON); User has pressed Call button — start Activity that can make a call (no data is passed in or returned) 1. Start the Activity if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); }
  • 15. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Avoid exceptions and crashes 15 Before starting an implicit Activity, use the package manager to check that there is a package with an Activity that matches the given criteria. Intent myIntent = new Intent(Intent.ACTION_CALL_BUTTON); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); }
  • 16. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Sending an implicit Intent with data URI 16 1. Create an Intent for action Intent intent = new Intent(Intent.ACTION_DIAL); 1. Provide data as a URI intent.setData(Uri.parse("tel:8005551234")); 1. Start the Activity if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); }
  • 17. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Providing the data as URI 17 Create an URI from a string using Uri.parse(String uri) ● Uri.parse("tel:8005551234") ● Uri.parse("geo:0,0?q=brooklyn%20bridge%2C%20brooklyn%2C%20ny") ● Uri.parse("http://www.android.com"); Uri documentation
  • 18. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Implicit Intent examples 18 Show a web page Uri uri = Uri.parse("http://www.google.com"); Intent it = new Intent(Intent.ACTION_VIEW,uri); startActivity(it); Dial a phone number Uri uri = Uri.parse("tel:8005551234"); Intent it = new Intent(Intent.ACTION_DIAL, uri); startActivity(it);
  • 19. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Sending an implicit Intent with extras 19 1. Create an Intent for an action Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); 1. Put extras String query = edittext.getText().toString(); intent.putExtra(SearchManager.QUERY, query)); 1. Start the Activity if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); }
  • 20. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Category 20 Additional information about the kind of component to handle the intent. ● CATEGORY_OPENABLE Only allow URIs of files that are openable ● CATEGORY_BROWSABLE Only an Activity that can start a web browser to display data referenced by the URI
  • 21. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Sending an implicit Intent with type and category 21 1. Create an Intent for an action Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); 1. Set mime type and category for additional information intent.setType("application/pdf"); // set MIME type intent.addCategory(Intent.CATEGORY_OPENABLE); continued on next slide...
  • 22. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Sending an implicit Intent with type and category 22 3. Start the Activity if (intent.resolveActivity(getPackageManager()) != null) { startActivityForResult(myIntent,ACTIVITY_REQUEST_CREATE_FILE); } 4. Process returned content URI in onActivityResult()
  • 23. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Common actions for an implicit Intent 23 Common actions include: ● ACTION_SET_ALARM ● ACTION_IMAGE_CAPTURE ● ACTION_CREATE_DOCUMENT ● ACTION_SENDTO ● and many more
  • 24. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Apps that handle common actions 24 Common actions are usually handled by installed apps (both system apps and other apps), such as: ● Alarm Clock, Calendar, Camera, Contacts ● Email, File Storage, Maps, Music/Video ● Notes, Phone, Search, Settings ● Text Messaging and Web Browsing ➔ List of common actions for an implicit intent ➔ List of all available actions
  • 25. Android Developer Fundamentals V2 Receiving an Implicit Intent 25
  • 26. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Register your app to receive an Intent 26 ● Declare one or more Intent filters for the Activity in AndroidManifest.xml ● Filter announces ability of Activity to accept an implicit Intent ● Filter puts conditions on the Intent that the Activity accepts
  • 27. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Intent filter in AndroidManifest.xml 27 <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"/> </intent-filter> </activity>
  • 28. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Intent filters: action and category 28 ● action — Match one or more action constants ○ android.intent.action.VIEW — matches any Intent with ACTION_VIEW ○ android.intent.action.SEND — matches any Intent with ACTION_SEND ● category — additional information (list of categories) ○ android.intent.category.BROWSABLE—can be started by web browser ○ android.intent.category.LAUNCHER—Show activity as launcher icon
  • 29. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Intent filters: data 29 ● data — Filter on data URIs, MIME type ○ android:scheme="https"—require URIs to be https protocol ○ android:host="developer.android.com"—only accept an Intent from specified hosts ○ android:mimeType="text/plain"—limit the acceptable types of documents
  • 30. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents 30 An Activity can have multiple filters <activity android:name="ShareActivity"> <intent-filter> <action android:name="android.intent.action.SEND"/> ... </intent-filter> <intent-filter> <action android:name="android.intent.action.SEND_MULTIPLE"/> ... </intent-filter> </activity> An Activity can have several filters
  • 31. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents A filter can have multiple actions & data <intent-filter> <action android:name="android.intent.action.SEND"/> <action android:name="android.intent.action.SEND_MULTIPLE"/> <category android:name="android.intent.category.DEFAULT"/> <data android:mimeType="image/*"/> <data android:mimeType="video/*"/> </intent-filter> 31
  • 32. Android Developer Fundamentals V2 Learn more 32
  • 33. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents Learn more ● Intent class documentation ● Uri documentation ● List of common apps that respond to implicit intents ● List of available actions ● List of categories ● Intent Filters 33
  • 34. Android Developer Fundamentals V2 This work is licensed under a Creative Commons Attribution 4.0 International License. Implicit Intents What's Next? 34 ● Concept Chapter: 2.3 Implicit Intents ● Practical: 2.3 Implicit Intents