SlideShare a Scribd company logo
1 of 33
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 intentDiego Grancini
 
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 semaswinbiju1652
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & DatabasesMuhammad 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; ShareAnuchit 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.pdfAbdullahMunir32
 
Tk2323 lecture 3 intent
Tk2323 lecture 3   intentTk2323 lecture 3   intent
Tk2323 lecture 3 intentMengChun Lam
 
Android Bootcamp Tanzania:intents
Android Bootcamp Tanzania:intentsAndroid Bootcamp Tanzania:intents
Android Bootcamp Tanzania:intentsDenis Minja
 
Android activity intents
Android activity intentsAndroid activity intents
Android activity intentsperpetrotech
 
Android activity intentsq
Android activity intentsqAndroid activity intentsq
Android activity intentsqperpetrotech
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdfssusere71a07
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx34ShreyaChauhan
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recieversUtkarsh Mankad
 
Using intents in android
Using intents in androidUsing intents in android
Using intents in androidOum Saokosal
 
Create an other activity lesson 3
Create an other activity lesson 3Create an other activity lesson 3
Create an other activity lesson 3Kalluri Vinay Reddy
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intentPERKYTORIALS
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptbharatt7
 

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 intents
Android activity intentsAndroid activity intents
Android activity intents
 
Android activity intentsq
Android activity intentsqAndroid activity intentsq
Android activity intentsq
 
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

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 

Recently uploaded (20)

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 

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.