SlideShare a Scribd company logo
1 of 18
Download to read offline
Intents &
Intent Filters
   codeandroid.org
Intents & Intents Filter

• Intents : request for an action to be
  performed (usually on a set of data)
• Intent Filters : register Activities, Services,
  and Broadcast Receivers (as being capable
  of performing an action on a set of data)
• Broadcast Receivers : listens to intents
Intents

• Support interaction between any
  application components available on an
  Android device
   • start a new Activity
   • broadcast messages (broadcast intents)
Intents
       Starting a new Activity

Intent intent = new Intent (......................);
startActivity(intent);
Intents
                   Starting a new Activity
Dial a number

Intent intent = new Intent (Intent.ACTION_DIAL, Uri.parse(“tel:93675359”));
startActivity(intent);

Launch a website

Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse(“http://codeandroid.org”));
startActivity(intent);
Intents
                     Starting a new Activity
Launch an Activity

 Intent intent = new Intent (this, HelloWorld.class);
 startActivity(intent);

Launch an Activity
 Intent intent = new Intent (this, HelloWorld.class);
 intent.putExtra(“title”,”Hello codeandroid”);
 startActivity(intent);
Intent Filters
AndroidManifest.xml

<activity android:name=”.HelloWorld”
          android:label=”@string/app_name”>
          <intent-filter>
               <action android:name=”android.intent.action.MAIN”/>
               <category android:name=”android.intent.category.LAUNCHER”/>
          </intent-filter>
</activity>

Launch Hello World

Intent intent = new Intent (this, HelloWorld.class);
startActivity(intent);
Intent Filters

• Required for Intent resolution to
  match Intents to Activities, Services, or
  BroadcastReceivers
• Most Intent Filters are declared in
  AndroidManifest.xml of an application
Intent Filters
AndroidManifest.xml

<activity android:name=”.HelloWorld”
          android:label=”@string/app_name”>
          <intent-filter>
               <action android:name=”org.codeandroid.intentstest.HelloWorld”/>
               <category android:name=”android.intent.category.DEFAULT”/>
          </intent-filter>
</activity>

Launch Hello World

Intent intent = new Intent (“org.codeandroid.intentstest.HelloWorld”);
startActivity(intent);
Intent Filters
AndroidManifest.xml
<activity android:name=”.HelloWorld”
           android:label=”@string/app_name”>
           <intent-filter>
                <action android:name=”android.intent.action.VIEW”/>
                <category android:name=”android.intent.category.DEFAULT”/>
                <category android:name=”android.intent.category.BROWSABLE”/>
                <data android:scheme=”http” android:host=”androidium.org”/>
           </intent-filter>
</activity>
Launch Hello World

Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse(“http://androidium.org”));
startActivity(intent);
Intent Filters
AndroidManifest.xml

<activity android:name=”.HelloWorld”
           android:label=”@string/app_name”>
           <intent-filter>
                <action android:name=”android.intent.action.VIEW”/>
                <category android:name=”android.intent.category.DEFAULT”/>
                <category android:name=”android.intent.category.BROWSABLE”/>
                <data android:scheme=”http”
                     android:host=”www.google.com”
                     android:pathPrefix=”/advanced_search”
                />
           </intent-filter>
</activity>
Intent Filters
AndroidManifest.xml
<activity android:name=”.HelloWorld”
           android:label=”@string/app_name”>
           <intent-filter>
                <action android:name=”android.intent.action.VIEW”/>
                <category android:name=”android.intent.category.DEFAULT”/>
                <category android:name=”android.intent.category.BROWSABLE”/>
                <data android:scheme=”codeandroid”/>
           </intent-filter>
</activity>
Launch Hello World

Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse(“codeandroid://”));
startActivity(intent);
Intents
               Launch the Android Market

Uri marketUri = Uri.parse(“http://market.android.com/search?q=pname:com.buuuk.buUuk”)
Intent intent = new Intent (Intent.ACTION_VIEW, marketUri);
startActivity(intent);



Uri marketUri = Uri.parse(“market://search?q=pname:com.buuuk.buUuk”)
Intent intent = new Intent (Intent.ACTION_VIEW, marketUri);
startActivity(intent);
Intents
      Broadcast Intents

• broadcast messages between
  components with the sendBroadcast
  method
• makes an application more open, by
  broadcasting to current and other
  applications
Intents
             Broadcast Intents


Intent intent = new
Intent(“org.codeandroid.intentstest.TestBroadcastReceiver”);
sendBroadcast(intent);
Broadcast Receivers

• listen to Broadcast Intents
• must be registered (either in code or
  within the app manifest
• use Intent Filter to specify which
  Intents it is listening for
Broadcast Receivers
                             registered inside code
IntentFilter filter = new IntentFilter(“org.codeandroid.intentstest.TestBroadcastReceiver”);
TestBroadcastReceiver receiver = new TestBroadcastReceiver();
registerReceiver(receiver, filter);


public class TestBroadcastReceiver extends Broadcast Receiver
{
  @Override
  public void onReceive(Context context, Intent intent)
  {
        (.................... do something here................)
    }
}
Broadcast Receivers
               register in app manifest
<receiver android:name=”CameraPressedReceiver”>
     <intent-filter>
           <action
           android:name=”android.intent.action.CAMERA_BUTTON”
        />
     </intent-filter>
</receiver>


 public class CameraPressed extends Broadcast Receiver
 {
   @Override
   public void onReceive(Context context, Intent intent)
   {
         (.................... do something here................)
     }
 }

More Related Content

What's hot

What's hot (20)

JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
 
05 intent
05 intent05 intent
05 intent
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming Basics
 
Android Navigation Component
Android Navigation ComponentAndroid Navigation Component
Android Navigation Component
 
Android UI
Android UIAndroid UI
Android UI
 
Android - Android Intent Types
Android - Android Intent TypesAndroid - Android Intent Types
Android - Android Intent Types
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Broadcast Receivers in Android
Broadcast Receivers in AndroidBroadcast Receivers in Android
Broadcast Receivers in Android
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Notification android
Notification androidNotification android
Notification android
 
C#.NET
C#.NETC#.NET
C#.NET
 
JDBC
JDBCJDBC
JDBC
 
javathreads
javathreadsjavathreads
javathreads
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Properties and indexers in C#
Properties and indexers in C#Properties and indexers in C#
Properties and indexers in C#
 
Android styles and themes
Android styles and themesAndroid styles and themes
Android styles and themes
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
[Android] Widget Event Handling
[Android] Widget Event Handling[Android] Widget Event Handling
[Android] Widget Event Handling
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 

Viewers also liked

Android Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver TutorialAndroid Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver Tutorial
Ahsanul Karim
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI Widgets
Ahsanul Karim
 
Android GPS Tutorial
Android GPS TutorialAndroid GPS Tutorial
Android GPS Tutorial
Ahsanul Karim
 

Viewers also liked (20)

Intent in android
Intent in androidIntent in android
Intent in android
 
Android Lesson 3 - Intent
Android Lesson 3 - IntentAndroid Lesson 3 - Intent
Android Lesson 3 - Intent
 
Android intents
Android intentsAndroid intents
Android intents
 
Android intent
Android intentAndroid intent
Android intent
 
Android Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver TutorialAndroid Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver Tutorial
 
[Android] Intent and Activity
[Android] Intent and Activity[Android] Intent and Activity
[Android] Intent and Activity
 
Android Lesson 2
Android Lesson 2Android Lesson 2
Android Lesson 2
 
Android Services
Android ServicesAndroid Services
Android Services
 
Introduction to Android Fragments
Introduction to Android FragmentsIntroduction to Android Fragments
Introduction to Android Fragments
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI Widgets
 
Strategic intent
Strategic intentStrategic intent
Strategic intent
 
Strategic intent
Strategic intentStrategic intent
Strategic intent
 
Menu in android
Menu in androidMenu in android
Menu in android
 
Android ppt
Android ppt Android ppt
Android ppt
 
Android Life Cycle
Android Life CycleAndroid Life Cycle
Android Life Cycle
 
The android activity lifecycle
The android activity lifecycleThe android activity lifecycle
The android activity lifecycle
 
Android adapters
Android adaptersAndroid adapters
Android adapters
 
Day 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location APIDay 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location API
 
Android GPS Tutorial
Android GPS TutorialAndroid GPS Tutorial
Android GPS Tutorial
 
Android - Broadcast Receiver
Android - Broadcast ReceiverAndroid - Broadcast Receiver
Android - Broadcast Receiver
 

Similar to Android: Intent, Intent Filter, Broadcast Receivers

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
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basics
Anton Narusberg
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
Utkarsh Mankad
 

Similar to Android: Intent, Intent Filter, Broadcast Receivers (20)

Introduction toandroid
Introduction toandroidIntroduction toandroid
Introduction toandroid
 
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
 
Intents are Awesome
Intents are AwesomeIntents are Awesome
Intents are Awesome
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Using intents in android
Using intents in androidUsing intents in android
Using intents in android
 
Native Android Development Practices
Native Android Development PracticesNative Android Development Practices
Native Android Development Practices
 
Android应用开发简介
Android应用开发简介Android应用开发简介
Android应用开发简介
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basics
 
An Introduction to Deep Linking and App Indexing Codelab
An Introduction to Deep Linking and App Indexing CodelabAn Introduction to Deep Linking and App Indexing Codelab
An Introduction to Deep Linking and App Indexing Codelab
 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
 
Android intents in android application-chapter7
Android intents in android application-chapter7Android intents in android application-chapter7
Android intents in android application-chapter7
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android Apps
 
Droidcon: Sean Owen: Driving Downloads via Intents- 29/10/2010
Droidcon: Sean Owen: Driving Downloads via Intents- 29/10/2010Droidcon: Sean Owen: Driving Downloads via Intents- 29/10/2010
Droidcon: Sean Owen: Driving Downloads via Intents- 29/10/2010
 
Android開発の基礎_20101218
Android開発の基礎_20101218Android開発の基礎_20101218
Android開発の基礎_20101218
 
Exercises broadcast receiver,incoming phone call
Exercises broadcast receiver,incoming phone callExercises broadcast receiver,incoming phone call
Exercises broadcast receiver,incoming phone call
 
Android Froyo
Android FroyoAndroid Froyo
Android Froyo
 
android level 3
android level 3android level 3
android level 3
 
Android Security Essentials
Android Security EssentialsAndroid Security Essentials
Android Security Essentials
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Android: Intent, Intent Filter, Broadcast Receivers

  • 1. Intents & Intent Filters codeandroid.org
  • 2. Intents & Intents Filter • Intents : request for an action to be performed (usually on a set of data) • Intent Filters : register Activities, Services, and Broadcast Receivers (as being capable of performing an action on a set of data) • Broadcast Receivers : listens to intents
  • 3. Intents • Support interaction between any application components available on an Android device • start a new Activity • broadcast messages (broadcast intents)
  • 4. Intents Starting a new Activity Intent intent = new Intent (......................); startActivity(intent);
  • 5. Intents Starting a new Activity Dial a number Intent intent = new Intent (Intent.ACTION_DIAL, Uri.parse(“tel:93675359”)); startActivity(intent); Launch a website Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse(“http://codeandroid.org”)); startActivity(intent);
  • 6. Intents Starting a new Activity Launch an Activity Intent intent = new Intent (this, HelloWorld.class); startActivity(intent); Launch an Activity Intent intent = new Intent (this, HelloWorld.class); intent.putExtra(“title”,”Hello codeandroid”); startActivity(intent);
  • 7. Intent Filters AndroidManifest.xml <activity android:name=”.HelloWorld” android:label=”@string/app_name”> <intent-filter> <action android:name=”android.intent.action.MAIN”/> <category android:name=”android.intent.category.LAUNCHER”/> </intent-filter> </activity> Launch Hello World Intent intent = new Intent (this, HelloWorld.class); startActivity(intent);
  • 8. Intent Filters • Required for Intent resolution to match Intents to Activities, Services, or BroadcastReceivers • Most Intent Filters are declared in AndroidManifest.xml of an application
  • 9. Intent Filters AndroidManifest.xml <activity android:name=”.HelloWorld” android:label=”@string/app_name”> <intent-filter> <action android:name=”org.codeandroid.intentstest.HelloWorld”/> <category android:name=”android.intent.category.DEFAULT”/> </intent-filter> </activity> Launch Hello World Intent intent = new Intent (“org.codeandroid.intentstest.HelloWorld”); startActivity(intent);
  • 10. Intent Filters AndroidManifest.xml <activity android:name=”.HelloWorld” android:label=”@string/app_name”> <intent-filter> <action android:name=”android.intent.action.VIEW”/> <category android:name=”android.intent.category.DEFAULT”/> <category android:name=”android.intent.category.BROWSABLE”/> <data android:scheme=”http” android:host=”androidium.org”/> </intent-filter> </activity> Launch Hello World Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse(“http://androidium.org”)); startActivity(intent);
  • 11. Intent Filters AndroidManifest.xml <activity android:name=”.HelloWorld” android:label=”@string/app_name”> <intent-filter> <action android:name=”android.intent.action.VIEW”/> <category android:name=”android.intent.category.DEFAULT”/> <category android:name=”android.intent.category.BROWSABLE”/> <data android:scheme=”http” android:host=”www.google.com” android:pathPrefix=”/advanced_search” /> </intent-filter> </activity>
  • 12. Intent Filters AndroidManifest.xml <activity android:name=”.HelloWorld” android:label=”@string/app_name”> <intent-filter> <action android:name=”android.intent.action.VIEW”/> <category android:name=”android.intent.category.DEFAULT”/> <category android:name=”android.intent.category.BROWSABLE”/> <data android:scheme=”codeandroid”/> </intent-filter> </activity> Launch Hello World Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse(“codeandroid://”)); startActivity(intent);
  • 13. Intents Launch the Android Market Uri marketUri = Uri.parse(“http://market.android.com/search?q=pname:com.buuuk.buUuk”) Intent intent = new Intent (Intent.ACTION_VIEW, marketUri); startActivity(intent); Uri marketUri = Uri.parse(“market://search?q=pname:com.buuuk.buUuk”) Intent intent = new Intent (Intent.ACTION_VIEW, marketUri); startActivity(intent);
  • 14. Intents Broadcast Intents • broadcast messages between components with the sendBroadcast method • makes an application more open, by broadcasting to current and other applications
  • 15. Intents Broadcast Intents Intent intent = new Intent(“org.codeandroid.intentstest.TestBroadcastReceiver”); sendBroadcast(intent);
  • 16. Broadcast Receivers • listen to Broadcast Intents • must be registered (either in code or within the app manifest • use Intent Filter to specify which Intents it is listening for
  • 17. Broadcast Receivers registered inside code IntentFilter filter = new IntentFilter(“org.codeandroid.intentstest.TestBroadcastReceiver”); TestBroadcastReceiver receiver = new TestBroadcastReceiver(); registerReceiver(receiver, filter); public class TestBroadcastReceiver extends Broadcast Receiver { @Override public void onReceive(Context context, Intent intent) { (.................... do something here................) } }
  • 18. Broadcast Receivers register in app manifest <receiver android:name=”CameraPressedReceiver”> <intent-filter> <action android:name=”android.intent.action.CAMERA_BUTTON” /> </intent-filter> </receiver> public class CameraPressed extends Broadcast Receiver { @Override public void onReceive(Context context, Intent intent) { (.................... do something here................) } }