SlideShare a Scribd company logo
UNIT 3
Android Notification
Toast Notification
Toast Notification
• Atoast notification is a message that
popsupon the surface of the window.
• It only fills the amountof space
required for the messageandthe
user's current activity remains visible
and interactive.
• Thenotification automatically
fades in and out, anddoesnot
accept interaction events.
• Because atoast canbe created
from a backgroundService, it
appears evenif the application isn't
visible.
Toast Message
Toast.makeText(
getApplicationContext(), // Context
R.string.toast_message, // Getstring resourceto display
Toast.LENGTH_LONG).show();// Makesure youcall show()
Status Bar
Notification
Status BarNotification
• Astatus bar notification adds anicon to the
system's status bar (with anoptional ticker- text
message) andan expandedmessage (notification
detail) in the "Notifications" window.
• Whenthe user selects the expanded message,
Android fires anIntent that is defined by the
notification (usually to launch anActivity).
• You can also configure the notification to alert the
user with a sound, a vibration, and flashing lights on
the device.
Icon and Ticker-textMessage
Code that DisplaysIcon/Ticker-text
// Geta referenceto the NotificationManager:
NotificationManager mNotificationManager =(NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
// Instantiate the Notification.
Notification mNotification =newNotification(R.drawable.android, "New
Alert, Pull medownto seeNotification details!",
System.currentTimeMillis());
....
...
mNotificationManager.notify(SIMPLE_NOTFICATION_ID,
mNotification);
Expanded Message (NotificationDetail)
• Appears whenicon/ticker-text is pulled down
Code that DisplaysExpanded
Message (Notification Detail)
// Define the Notification's expandedmessage(notification detail)
// andIntent.Thenotification detail messageis the onethat gets
// displayed whena user drags the notification downward.
CharSequencecontentTitle ="Notification Details.";
CharSequencecontentText ="Goto JavaPassion.com byclicking me";
....
...
// Sets the contentView field to be a view with the standard "Latest Event"
// layout. "mPendingIntent" is anintent to launch whenthe user clicks
// the expandednotification
mNotification.setLatestEventInfo(getApplicationContext(),
contentTitle,
contentText,
mPendingIntent);
Activity That Gets StartedWhen
Notification Detail isClicked
Code that Starts an Activitywhen
Notification Detail isclicked
// TheIntent is to define an action that gets executed when a
// user clicks the notification detail.
intent notifyIntent =new Intent(
android.content.Intent.ACTION_VIEW, Uri
.parse("http://www.javapassion.com"));
// ThePendingIntentcanbe handedto other applications so that they can
// perform the action you described on your behalf at a later time.
// Bygiving a PendingIntent to another application, you are granting it the
// right to perform the operation you have specified as if the other application
// was yourself (with the samepermissions and identity).
PendingIntent mPendingIntent = PendingIntent.getActivity(
StatusBarNotification.this, 0, notifyIntent,
android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
// Sets the contentView field to bea view with the standard "Latest Event"
// layout. "mPendingIntent" is anintent to launch when the user clicks
// the expandednotification
mNotification.setLatestEventInfo(getApplicationContext(),
contentTitle,
contentText,
PendingIntent
• PendingIntent is basically an object that wraps another Intent object. Then it
can be passed to a foreign application where you’re granting that app the right
to perform the operation, i.e., execute the intent as if it were executed from
your own app’s process (same permission and identity). For security reasons
you should always pass explicit intents to a PendingIntent rather than being
implicit.
• Instances of this class are created with getActivity(Context, int, Intent,
int), getBroadcast(Context, int, Intent, int), and getService(Context, int, Intent,
int); the returned object can be handed to other applications so that they can
perform the action you described on your behalf at a later time.
Android Intents
Agenda
What is Intent?
Why Intent?
Types of Intents?
How Intents are received?
How Intents are resolved?
What is an
Intent?
➢ It is a message passing framework that is used to carry out
interaction between Activities(and also other android
building blocks such as services and broadcast Receivers)
➢ Intent contains an action carrying some information.
➢ Intent is used to communicate between android
components.
○ To start an activity
○ To start a service
○ To deliver a broadcast.
• There are separate mechanisms for delivering intents to each type of component − activities,
services, and broadcast receivers.
• 1.Context.startActivity()
• The Intent object is passed to this method to launch a new activity or get an existing activity to
do something new.
• 2.Context.startService()
• The Intent object is passed to this method to initiate a service or deliver new instructions to an
ongoing service.
• 3.Context.sendBroadcast()
• The Intent object is passed to this method to deliver the message to all interested broadcast
receivers.
Why
Intent?
➢ Intent is used to communicate, share data
between components.
➢ Intent contains the following things.
○ Component Name
○ Action
○ Data
○ Extras
○ Category
○ Flags
Intent Objects
• An Intent object is a bundle of information which is used by the component that receives the
intent as well as information used by the Android system.
• An Intent object can contain the following components
• Action
• This is mandatory part of the Intent object and is a string naming the action to be performed —
or, in the case of broadcast intents, the action that took place and is being reported. The action
largely determines how the rest of the intent object is structured . The Intent class defines a
number of action constants corresponding to different intents.
• Eg: ACTION_WEB_SEARCH
• Perform a web search.
• ACTION_SEND
• Deliver some data to someone else.
• ACTION_SEARCH
• Perform a search.
• The action in an Intent object can be set by the setAction() method and read by getAction().
Data
• Adds a data specification to an intent filter. The specification can be just a data type (the
mimeType attribute), just a URI, or both a data type and a URI. The setData() method specifies
data only as a URI, setType() specifies it only as a MIME type, and setDataAndType() specifies it
as both a URI and a MIME type. The URI is read by getData() and the type by getType().
• Category
• The category is an optional part of Intent object and it's a string containing additional information about the
kind of component that should handle the intent. The addCategory() method places a category in an Intent
object, removeCategory() deletes a category previously added, and getCategories() gets the set of all
categories currently in the object.eg
• CATEGORY_APP_MESSAGING
• Used with ACTION_MAIN to launch the messaging application
• CATEGORY_APP_MUSIC
• Used with ACTION_MAIN to launch the music application.
• CATEGORY_DEFAULT
• Set if the activity should be an option for the default action to perform on a piece of data.
• To receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent
filter. The methods startActivity() treat all intents as if they declared the CATEGORY_DEFAULT
category. If you do not declare this category in your intent filter, no implicit intents will resolve
to your activity.
• Extras
• This will be in key-value pairs for additional information that should be
delivered to the component handling the intent. The extras can be set and
read using the putExtras() and getExtras() methods respectively.
• Flags
• These flags are optional part of Intent object and instruct the Android system how to launch an activity, and
how to treat it after it's launched etc.
• FLAG_ACTIVITY_CLEAR_TASK
• If set in an Intent passed to Context.startActivity(), this flag will cause any existing task that would be
associated with the activity to be cleared before the activity is started. That is, the activity becomes the new
root of an otherwise empty task, and any old activities are finished. This can only be used in conjunction
with FLAG_ACTIVITY_NEW_TASK.
• FLAG_ACTIVITY_NEW_TASK
• This flag is generally used by activities that want to present a "launcher" style behavior: they give the user a
list of separate things that can be done, which otherwise run completely independently of the activity
launching them.
• FLAG_ACTIVITY_CLEAR_TOP
• If set, and the activity being launched is already running in the current task, then instead of launching a new
instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered
to the (now on top) old activity as a new Intent.
• Component Name
• This optional field is an android ComponentName object
representing either Activity, Service or BroadcastReceiver
class. If it is set, the Intent object is delivered to an instance
of the designated class otherwise Android uses other
information in the Intent object to locate a suitable target.
• The component name is set by setComponent(), setClass(),
or setClassName() and read by getComponent().
Types of
Intents?
➢ Explicit Intents
➢ Implicit Intents
Explicit
Intents
➢ Used to launch a specific component like
activity or a service.
➢ In this case, android system directly
forwards this intent to that specific
component.
➢ It is faster.
➢ Always use explicit intents if you know the
specific activity or service .
Interaction among activities
• To navigate to an activity from another activity ,we
make use of an intent.
1. Create an intent Object with two parameter. The first
parameter is context and second parameter is the
second activity to navigate.
• Context is an object provided by Android runtime
environment to the app.It contains the global
information about the environment in which application
is running.
• 2. Pass this Intent object to startActivity() method.
Implicit
Intent
➢ Specifies an action that can invoke an app
on the device that can perform the action.
➢ Useful when your app can not perform the
action but other apps do and you let user to
pick up the app.
➢ Its possible that there may not be any app
that handles the implicit intent.
How Intents are
received?
➢ Till now we have seen how intents are used
to invoke some other components. Now lets
explore how these components receive
these intents.
➢ Receiving Implicit Intents
➢ Receiving Explicit Intents
○ Explicit Intents are directly delivered to target as
intent has the target component class specified in it.
Receiving Implicit
Intents
➢ Your app should advertise what intents it can
handle using <intent-filter> tag in the
manifest file under <activity> or <service> or
<receiver> tags.
➢ You can mention one or more of these three
elements under <intent-filter>
○ action
○ data
○ category
Receiving Implicit
Intents
Ex:
<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>
How Intents are
resolved?
➢ When the system receives an implicit intent,
it searches the component by comparing the
intent to intent filter based on these aspects.
○ The Intent action(Action Test)
■ Ex: ACTION_SEND
○ The Intent Category(Category Test)
■ Ex: CATEGORY_HOME
○ The Data(Data Test)
■ Ex: android:mimetype=”video/mpeg”
Intent Filters
• We have seen how an Intent has been used to call an another
activity. Android OS uses filters to pinpoint the set of Activities,
Services, and Broadcast receivers that can handle the Intent with
help of specified set of action, categories, data scheme associated
with an Intent.
• We will use <intent-filter> element in the manifest file to list down
actions, categories and data types associated with any activity,
service, or broadcast receiver.

More Related Content

Similar to unit3.pptx

Android App Development - 02 Activity and intent
Android App Development - 02 Activity and intentAndroid App Development - 02 Activity and intent
Android App Development - 02 Activity and intent
Diego Grancini
 
ANDROID
ANDROIDANDROID
ANDROID
DrMeftahZouai
 
Lab1-android
Lab1-androidLab1-android
Lab1-android
Lilia Sfaxi
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last sem
aswinbiju1652
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
Muhammad Sajid
 
Android App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; ShareAndroid App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; Share
Anuchit Chalothorn
 
Mobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfMobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdf
AbdullahMunir32
 
Tk2323 lecture 3 intent
Tk2323 lecture 3   intentTk2323 lecture 3   intent
Tk2323 lecture 3 intent
MengChun Lam
 
Android Bootcamp Tanzania:intents
Android Bootcamp Tanzania:intentsAndroid Bootcamp Tanzania:intents
Android Bootcamp Tanzania:intents
Denis Minja
 
Android activity intentsq
Android activity intentsqAndroid activity intentsq
Android activity intentsq
perpetrotech
 
Android activity intents
Android activity intentsAndroid activity intents
Android activity intents
perpetrotech
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdf
ssusere71a07
 
Level 1 &amp; 2
Level 1 &amp; 2Level 1 &amp; 2
Level 1 &amp; 2
skumartarget
 
Android development session 2 - intent and activity
Android development   session 2 - intent and activityAndroid development   session 2 - intent and activity
Android development session 2 - intent and activity
Farabi Technology Middle East
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
34ShreyaChauhan
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
Utkarsh Mankad
 
Using intents in android
Using intents in androidUsing intents in android
Using intents in android
Oum Saokosal
 
Create an other activity lesson 3
Create an other activity lesson 3Create an other activity lesson 3
Create an other activity lesson 3
Kalluri Vinay Reddy
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
PERKYTORIALS
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.ppt
bharatt7
 

Similar to unit3.pptx (20)

Android App Development - 02 Activity and intent
Android App Development - 02 Activity and intentAndroid App Development - 02 Activity and intent
Android App Development - 02 Activity and intent
 
ANDROID
ANDROIDANDROID
ANDROID
 
Lab1-android
Lab1-androidLab1-android
Lab1-android
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last sem
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
Android App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; ShareAndroid App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; Share
 
Mobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfMobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdf
 
Tk2323 lecture 3 intent
Tk2323 lecture 3   intentTk2323 lecture 3   intent
Tk2323 lecture 3 intent
 
Android Bootcamp Tanzania:intents
Android Bootcamp Tanzania:intentsAndroid Bootcamp Tanzania:intents
Android Bootcamp Tanzania:intents
 
Android activity intentsq
Android activity intentsqAndroid activity intentsq
Android activity intentsq
 
Android activity intents
Android activity intentsAndroid activity intents
Android activity intents
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdf
 
Level 1 &amp; 2
Level 1 &amp; 2Level 1 &amp; 2
Level 1 &amp; 2
 
Android development session 2 - intent and activity
Android development   session 2 - intent and activityAndroid development   session 2 - intent and activity
Android development session 2 - intent and activity
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
 
Using intents in android
Using intents in androidUsing intents in android
Using intents in android
 
Create an other activity lesson 3
Create an other activity lesson 3Create an other activity lesson 3
Create an other activity lesson 3
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.ppt
 

Recently uploaded

A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
DharmaBanothu
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
ijaia
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
ijseajournal
 
Zener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and ApplicationsZener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and Applications
Shiny Christobel
 
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Transcat
 
Bituminous road construction project based learning report
Bituminous road construction project based learning reportBituminous road construction project based learning report
Bituminous road construction project based learning report
CE19KaushlendraKumar
 
Levelised Cost of Hydrogen (LCOH) Calculator Manual
Levelised Cost of Hydrogen  (LCOH) Calculator ManualLevelised Cost of Hydrogen  (LCOH) Calculator Manual
Levelised Cost of Hydrogen (LCOH) Calculator Manual
Massimo Talia
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
Kamal Acharya
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
Divyanshu
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
upoux
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
Kamal Acharya
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
VANDANAMOHANGOUDA
 
FULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back EndFULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back End
PreethaV16
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
vmspraneeth
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
PreethaV16
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
sydezfe
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
21UME003TUSHARDEB
 
Unit -II Spectroscopy - EC I B.Tech.pdf
Unit -II Spectroscopy - EC  I B.Tech.pdfUnit -II Spectroscopy - EC  I B.Tech.pdf
Unit -II Spectroscopy - EC I B.Tech.pdf
TeluguBadi
 

Recently uploaded (20)

A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
 
Zener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and ApplicationsZener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and Applications
 
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
 
Bituminous road construction project based learning report
Bituminous road construction project based learning reportBituminous road construction project based learning report
Bituminous road construction project based learning report
 
Levelised Cost of Hydrogen (LCOH) Calculator Manual
Levelised Cost of Hydrogen  (LCOH) Calculator ManualLevelised Cost of Hydrogen  (LCOH) Calculator Manual
Levelised Cost of Hydrogen (LCOH) Calculator Manual
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
 
FULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back EndFULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back End
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
 
Unit -II Spectroscopy - EC I B.Tech.pdf
Unit -II Spectroscopy - EC  I B.Tech.pdfUnit -II Spectroscopy - EC  I B.Tech.pdf
Unit -II Spectroscopy - EC I B.Tech.pdf
 

unit3.pptx

  • 4. Toast Notification • Atoast notification is a message that popsupon the surface of the window. • It only fills the amountof space required for the messageandthe user's current activity remains visible and interactive. • Thenotification automatically fades in and out, anddoesnot accept interaction events. • Because atoast canbe created from a backgroundService, it appears evenif the application isn't visible.
  • 5. Toast Message Toast.makeText( getApplicationContext(), // Context R.string.toast_message, // Getstring resourceto display Toast.LENGTH_LONG).show();// Makesure youcall show()
  • 7. Status BarNotification • Astatus bar notification adds anicon to the system's status bar (with anoptional ticker- text message) andan expandedmessage (notification detail) in the "Notifications" window. • Whenthe user selects the expanded message, Android fires anIntent that is defined by the notification (usually to launch anActivity). • You can also configure the notification to alert the user with a sound, a vibration, and flashing lights on the device.
  • 9. Code that DisplaysIcon/Ticker-text // Geta referenceto the NotificationManager: NotificationManager mNotificationManager =(NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Instantiate the Notification. Notification mNotification =newNotification(R.drawable.android, "New Alert, Pull medownto seeNotification details!", System.currentTimeMillis()); .... ... mNotificationManager.notify(SIMPLE_NOTFICATION_ID, mNotification);
  • 10. Expanded Message (NotificationDetail) • Appears whenicon/ticker-text is pulled down
  • 11. Code that DisplaysExpanded Message (Notification Detail) // Define the Notification's expandedmessage(notification detail) // andIntent.Thenotification detail messageis the onethat gets // displayed whena user drags the notification downward. CharSequencecontentTitle ="Notification Details."; CharSequencecontentText ="Goto JavaPassion.com byclicking me"; .... ... // Sets the contentView field to be a view with the standard "Latest Event" // layout. "mPendingIntent" is anintent to launch whenthe user clicks // the expandednotification mNotification.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, mPendingIntent);
  • 12. Activity That Gets StartedWhen Notification Detail isClicked
  • 13. Code that Starts an Activitywhen Notification Detail isclicked // TheIntent is to define an action that gets executed when a // user clicks the notification detail. intent notifyIntent =new Intent( android.content.Intent.ACTION_VIEW, Uri .parse("http://www.javapassion.com")); // ThePendingIntentcanbe handedto other applications so that they can // perform the action you described on your behalf at a later time. // Bygiving a PendingIntent to another application, you are granting it the // right to perform the operation you have specified as if the other application // was yourself (with the samepermissions and identity). PendingIntent mPendingIntent = PendingIntent.getActivity( StatusBarNotification.this, 0, notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK); // Sets the contentView field to bea view with the standard "Latest Event" // layout. "mPendingIntent" is anintent to launch when the user clicks // the expandednotification mNotification.setLatestEventInfo(getApplicationContext(), contentTitle, contentText,
  • 14. PendingIntent • PendingIntent is basically an object that wraps another Intent object. Then it can be passed to a foreign application where you’re granting that app the right to perform the operation, i.e., execute the intent as if it were executed from your own app’s process (same permission and identity). For security reasons you should always pass explicit intents to a PendingIntent rather than being implicit. • Instances of this class are created with getActivity(Context, int, Intent, int), getBroadcast(Context, int, Intent, int), and getService(Context, int, Intent, int); the returned object can be handed to other applications so that they can perform the action you described on your behalf at a later time.
  • 16. Agenda What is Intent? Why Intent? Types of Intents? How Intents are received? How Intents are resolved?
  • 17. What is an Intent? ➢ It is a message passing framework that is used to carry out interaction between Activities(and also other android building blocks such as services and broadcast Receivers) ➢ Intent contains an action carrying some information. ➢ Intent is used to communicate between android components. ○ To start an activity ○ To start a service ○ To deliver a broadcast.
  • 18. • There are separate mechanisms for delivering intents to each type of component − activities, services, and broadcast receivers. • 1.Context.startActivity() • The Intent object is passed to this method to launch a new activity or get an existing activity to do something new. • 2.Context.startService() • The Intent object is passed to this method to initiate a service or deliver new instructions to an ongoing service. • 3.Context.sendBroadcast() • The Intent object is passed to this method to deliver the message to all interested broadcast receivers.
  • 19. Why Intent? ➢ Intent is used to communicate, share data between components. ➢ Intent contains the following things. ○ Component Name ○ Action ○ Data ○ Extras ○ Category ○ Flags
  • 20. Intent Objects • An Intent object is a bundle of information which is used by the component that receives the intent as well as information used by the Android system. • An Intent object can contain the following components • Action • This is mandatory part of the Intent object and is a string naming the action to be performed — or, in the case of broadcast intents, the action that took place and is being reported. The action largely determines how the rest of the intent object is structured . The Intent class defines a number of action constants corresponding to different intents. • Eg: ACTION_WEB_SEARCH • Perform a web search. • ACTION_SEND • Deliver some data to someone else. • ACTION_SEARCH • Perform a search. • The action in an Intent object can be set by the setAction() method and read by getAction().
  • 21. Data • Adds a data specification to an intent filter. The specification can be just a data type (the mimeType attribute), just a URI, or both a data type and a URI. The setData() method specifies data only as a URI, setType() specifies it only as a MIME type, and setDataAndType() specifies it as both a URI and a MIME type. The URI is read by getData() and the type by getType(). • Category • The category is an optional part of Intent object and it's a string containing additional information about the kind of component that should handle the intent. The addCategory() method places a category in an Intent object, removeCategory() deletes a category previously added, and getCategories() gets the set of all categories currently in the object.eg • CATEGORY_APP_MESSAGING • Used with ACTION_MAIN to launch the messaging application • CATEGORY_APP_MUSIC • Used with ACTION_MAIN to launch the music application. • CATEGORY_DEFAULT • Set if the activity should be an option for the default action to perform on a piece of data. • To receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent filter. The methods startActivity() treat all intents as if they declared the CATEGORY_DEFAULT category. If you do not declare this category in your intent filter, no implicit intents will resolve to your activity.
  • 22. • Extras • This will be in key-value pairs for additional information that should be delivered to the component handling the intent. The extras can be set and read using the putExtras() and getExtras() methods respectively.
  • 23. • Flags • These flags are optional part of Intent object and instruct the Android system how to launch an activity, and how to treat it after it's launched etc. • FLAG_ACTIVITY_CLEAR_TASK • If set in an Intent passed to Context.startActivity(), this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started. That is, the activity becomes the new root of an otherwise empty task, and any old activities are finished. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK. • FLAG_ACTIVITY_NEW_TASK • This flag is generally used by activities that want to present a "launcher" style behavior: they give the user a list of separate things that can be done, which otherwise run completely independently of the activity launching them. • FLAG_ACTIVITY_CLEAR_TOP • If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.
  • 24. • Component Name • This optional field is an android ComponentName object representing either Activity, Service or BroadcastReceiver class. If it is set, the Intent object is delivered to an instance of the designated class otherwise Android uses other information in the Intent object to locate a suitable target. • The component name is set by setComponent(), setClass(), or setClassName() and read by getComponent().
  • 25. Types of Intents? ➢ Explicit Intents ➢ Implicit Intents
  • 26. Explicit Intents ➢ Used to launch a specific component like activity or a service. ➢ In this case, android system directly forwards this intent to that specific component. ➢ It is faster. ➢ Always use explicit intents if you know the specific activity or service .
  • 27. Interaction among activities • To navigate to an activity from another activity ,we make use of an intent. 1. Create an intent Object with two parameter. The first parameter is context and second parameter is the second activity to navigate. • Context is an object provided by Android runtime environment to the app.It contains the global information about the environment in which application is running. • 2. Pass this Intent object to startActivity() method.
  • 28. Implicit Intent ➢ Specifies an action that can invoke an app on the device that can perform the action. ➢ Useful when your app can not perform the action but other apps do and you let user to pick up the app. ➢ Its possible that there may not be any app that handles the implicit intent.
  • 29. How Intents are received? ➢ Till now we have seen how intents are used to invoke some other components. Now lets explore how these components receive these intents. ➢ Receiving Implicit Intents ➢ Receiving Explicit Intents ○ Explicit Intents are directly delivered to target as intent has the target component class specified in it.
  • 30. Receiving Implicit Intents ➢ Your app should advertise what intents it can handle using <intent-filter> tag in the manifest file under <activity> or <service> or <receiver> tags. ➢ You can mention one or more of these three elements under <intent-filter> ○ action ○ data ○ category
  • 31. Receiving Implicit Intents Ex: <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>
  • 32. How Intents are resolved? ➢ When the system receives an implicit intent, it searches the component by comparing the intent to intent filter based on these aspects. ○ The Intent action(Action Test) ■ Ex: ACTION_SEND ○ The Intent Category(Category Test) ■ Ex: CATEGORY_HOME ○ The Data(Data Test) ■ Ex: android:mimetype=”video/mpeg”
  • 33. Intent Filters • We have seen how an Intent has been used to call an another activity. Android OS uses filters to pinpoint the set of Activities, Services, and Broadcast receivers that can handle the Intent with help of specified set of action, categories, data scheme associated with an Intent. • We will use <intent-filter> element in the manifest file to list down actions, categories and data types associated with any activity, service, or broadcast receiver.