SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
7
 Intent & Share
 Anuchit Chalothorn
 anoochit@gmail.com

Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Intent
Intents are asynchronous messages which
allow Android components to request
functionality from other components of the
Android system.




Ref: http://developer.android.com/reference/android/content/Intent.html
Intent to another activity
Intent to the Android system to starts another
activity

Intent intent = new Intent(this,NewActivity.class);
startActivity(intent);
Intent with data
An Intent can contain data. This data can be
used by the receiving component. As data it
may send the URL to the browser component
which this browser should open and display.

String url="http://google.com";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.sendData(Uri.parse(url));
startActivity(intent);
Explicit Intents
Explicit intents explicitly defines the component
which should be called by the Android system,
by using the Java class as identifier.

Intent i = new Intent(this,NewActivity.class);
i.putExtra("Value1", "This value one for ActivityTwo ");
i.putExtra("Value2", "This value two ActivityTwo");
startActivity(i);
Implicit Intents
Implicit intents specify the action which should
be performed and optionally data which
provides data for the action.

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.sendData(Uri.parse("http://google.com"));
startActivity(intent);
Using the share intent
Lots of Android applications allow you to share
some data with other people, e.g. the
Facebook, G+, Gmail and Twitter application.
You can send data to one of this components.
Share Intent Example
You can send data to one of this components.

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(android.content.Intent.EXTRA_TEXT,
"News for you!");
startActivity(intent);
Receive Intent data
The component which receives the Intent can
use the getIntent().getExtras() method call to
get the extra data.
Bundle extras = getIntent().getExtras();
if (extras != null) {
   String value1 = extras.getString(Intent.EXTRA_TEXT);
}
Intent Filters
If an Intents is send to the Android system, it
will determine suitable applications for this
Intents. If several components have been
registered for this type of Intents, Android offers
the user the choice to open one of them.
Intent Filters
An Intent Filter declares the capabilities of a
component. It specifies what an activity or
service can do and what types of broadcasts a
Receiver can handle. It allows the
corresponding component to receive Intents of
the declared type. IntentFilters are typically
defined via the AndroidManifest.xml file
Register your Activity as Browser

Register an Activity for the Intent which is
triggered when someone wants to open a
webpage
<activity android:name=".BrowserActivitiy" android:label="
@string/app_name">
  <intent-filter>
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.DEFAULT" />
     <data android:scheme="http"/>
  </intent-filter>
</activity>
Register your Activity for the Share Intent

Register an Activity for the ACTION_SEND
Intent for the text/plain mime type.
<activity
  android:name=".ActivityTest"
    android:label="@string/app_name" >
    <intent-filter>
      <action android:name="android.intent.action.SEND" />
      <category android:name="android.intent.category.DEFAULT" />
      <data android:mimeType="text/plain" />
    </intent-filter>
</activity>
Workshop: Explicit Intents
Create 2 Activities, first activity has a edit text
and button after push the button it 'll sent data
in edit text to the second activity.
Workshop: Implicit Intents
Create an app to use a Spinner to select the
Intent which should get trigger :
   ● Open Browser
     ○ Intent.ACTION_VIEW
     ○ Uri.parse("http://google.com");
  ● Call Someone
     ○ Intent.ACTION_CALL
     ○ Uri.parse("tel:0891234567");
  ● Dial
     ○ Intent.ACTION_DIAL
     ○ Uri.parse("tel:0891234567");
Workshop: Implicit Intents
  ● Show Map
    ○ Intent.ACTION_VIEW
    ○ Uri.parse("geo:0,0?q=100.00,15.00");
  ● Search on Map
    ○ Intent.ACTION_VIEW
    ○ Uri.parse("geo:0,0?q=Bluecup coffee");
Workshop: Share Intent
Create App with simple share, to share text in
edit text to another application.

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, shareText);
startActivity(intent);
End

Contenu connexe

Tendances

B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intentPERKYTORIALS
 
[Android] Intent and Activity
[Android] Intent and Activity[Android] Intent and Activity
[Android] Intent and ActivityNikmesoft Ltd
 
Android Intent and intent filters
Android Intent and intent filtersAndroid Intent and intent filters
Android Intent and intent filtersGowtham Kumar
 
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 intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recieversUtkarsh Mankad
 
08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)Oum Saokosal
 
Develop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxDevelop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxvishal choudhary
 
Using intents in android
Using intents in androidUsing intents in android
Using intents in androidOum Saokosal
 
Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & IntentsLope Emano
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recieversUtkarsh Mankad
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycleAhsanul Karim
 

Tendances (20)

B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
[Android] Intent and Activity
[Android] Intent and Activity[Android] Intent and Activity
[Android] Intent and Activity
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
Android Intent and intent filters
Android Intent and intent filtersAndroid Intent and intent filters
Android Intent and intent filters
 
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 intents in android application-chapter7
Android intents in android application-chapter7Android intents in android application-chapter7
Android intents in android application-chapter7
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
 
08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)
 
Develop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxDevelop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptx
 
Using intents in android
Using intents in androidUsing intents in android
Using intents in android
 
Intents are Awesome
Intents are AwesomeIntents are Awesome
Intents are Awesome
 
Android app
Android appAndroid app
Android app
 
Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & Intents
 
Android Lesson 2
Android Lesson 2Android Lesson 2
Android Lesson 2
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
 
07 intent
07 intent07 intent
07 intent
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycle
 
Activity & Shared Preference
Activity & Shared PreferenceActivity & Shared Preference
Activity & Shared Preference
 
Android Components
Android ComponentsAndroid Components
Android Components
 

Similaire à Android App Development 07 : Intent &amp; Share

MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx34ShreyaChauhan
 
Intent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptIntent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptBirukMarkos
 
Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database faiz324545
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & DatabasesMuhammad Sajid
 
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
 
3-Implicit Intents.pptx
3-Implicit Intents.pptx3-Implicit Intents.pptx
3-Implicit Intents.pptxab2478037
 
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
 
MAD-Lec8 Spinner Adapater and Intents (1).ppt
MAD-Lec8 Spinner Adapater and Intents (1).pptMAD-Lec8 Spinner Adapater and Intents (1).ppt
MAD-Lec8 Spinner Adapater and Intents (1).pptAnsarAhmad57
 
Android Application Components-BroadcastReceiver_Content Provider.pptx
Android Application Components-BroadcastReceiver_Content Provider.pptxAndroid Application Components-BroadcastReceiver_Content Provider.pptx
Android Application Components-BroadcastReceiver_Content Provider.pptxKNANTHINIMCA
 
Hello android world
Hello android worldHello android world
Hello android worldeleksdev
 
Android developer interview questions with answers pdf
Android developer interview questions with answers pdfAndroid developer interview questions with answers pdf
Android developer interview questions with answers pdfazlist247
 
Android webinar class_3
Android webinar class_3Android webinar class_3
Android webinar class_3Edureka!
 

Similaire à Android App Development 07 : Intent &amp; Share (20)

MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
 
Android Intent.pptx
Android Intent.pptxAndroid Intent.pptx
Android Intent.pptx
 
Tut123456.pdf
Tut123456.pdfTut123456.pdf
Tut123456.pdf
 
ANDROID
ANDROIDANDROID
ANDROID
 
Intent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptIntent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).ppt
 
Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database
 
unit3.pptx
unit3.pptxunit3.pptx
unit3.pptx
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
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
 
3-Implicit Intents.pptx
3-Implicit Intents.pptx3-Implicit Intents.pptx
3-Implicit Intents.pptx
 
Ppt 2 android_basics
Ppt 2 android_basicsPpt 2 android_basics
Ppt 2 android_basics
 
Level 1 &amp; 2
Level 1 &amp; 2Level 1 &amp; 2
Level 1 &amp; 2
 
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
 
MAD-Lec8 Spinner Adapater and Intents (1).ppt
MAD-Lec8 Spinner Adapater and Intents (1).pptMAD-Lec8 Spinner Adapater and Intents (1).ppt
MAD-Lec8 Spinner Adapater and Intents (1).ppt
 
Android Application Components-BroadcastReceiver_Content Provider.pptx
Android Application Components-BroadcastReceiver_Content Provider.pptxAndroid Application Components-BroadcastReceiver_Content Provider.pptx
Android Application Components-BroadcastReceiver_Content Provider.pptx
 
Hello android world
Hello android worldHello android world
Hello android world
 
Lab1-android
Lab1-androidLab1-android
Lab1-android
 
Android developer interview questions with answers pdf
Android developer interview questions with answers pdfAndroid developer interview questions with answers pdf
Android developer interview questions with answers pdf
 
Android webinar class_3
Android webinar class_3Android webinar class_3
Android webinar class_3
 

Plus de Anuchit Chalothorn (20)

Flutter Workshop 2021 @ ARU
Flutter Workshop 2021 @ ARUFlutter Workshop 2021 @ ARU
Flutter Workshop 2021 @ ARU
 
Flutter workshop @ bang saen 2020
Flutter workshop @ bang saen 2020Flutter workshop @ bang saen 2020
Flutter workshop @ bang saen 2020
 
13 web service integration
13 web service integration13 web service integration
13 web service integration
 
09 material design
09 material design09 material design
09 material design
 
05 binding and action
05 binding and action05 binding and action
05 binding and action
 
04 layout design and basic widget
04 layout design and basic widget04 layout design and basic widget
04 layout design and basic widget
 
03 activity life cycle
03 activity life cycle03 activity life cycle
03 activity life cycle
 
02 create your first app
02 create your first app02 create your first app
02 create your first app
 
01 introduction
01 introduction 01 introduction
01 introduction
 
Material Theme
Material ThemeMaterial Theme
Material Theme
 
00 Android Wear Setup Emulator
00 Android Wear Setup Emulator00 Android Wear Setup Emulator
00 Android Wear Setup Emulator
 
MongoDB Replication Cluster
MongoDB Replication ClusterMongoDB Replication Cluster
MongoDB Replication Cluster
 
MongoDB Shard Cluster
MongoDB Shard ClusterMongoDB Shard Cluster
MongoDB Shard Cluster
 
IT Automation with Chef
IT Automation with ChefIT Automation with Chef
IT Automation with Chef
 
IT Automation with Puppet Enterprise
IT Automation with Puppet EnterpriseIT Automation with Puppet Enterprise
IT Automation with Puppet Enterprise
 
Using PhoneGap Command Line
Using PhoneGap Command LineUsing PhoneGap Command Line
Using PhoneGap Command Line
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
OpenStack Cheat Sheet V2
OpenStack Cheat Sheet V2OpenStack Cheat Sheet V2
OpenStack Cheat Sheet V2
 
REST API with CakePHP
REST API with CakePHPREST API with CakePHP
REST API with CakePHP
 
Open Stack Cheat Sheet V1
Open Stack Cheat Sheet V1Open Stack Cheat Sheet V1
Open Stack Cheat Sheet V1
 

Android App Development 07 : Intent &amp; Share

  • 1. 7 Intent & Share Anuchit Chalothorn anoochit@gmail.com Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  • 2. Intent Intents are asynchronous messages which allow Android components to request functionality from other components of the Android system. Ref: http://developer.android.com/reference/android/content/Intent.html
  • 3. Intent to another activity Intent to the Android system to starts another activity Intent intent = new Intent(this,NewActivity.class); startActivity(intent);
  • 4. Intent with data An Intent can contain data. This data can be used by the receiving component. As data it may send the URL to the browser component which this browser should open and display. String url="http://google.com"; Intent intent = new Intent(Intent.ACTION_VIEW); intent.sendData(Uri.parse(url)); startActivity(intent);
  • 5. Explicit Intents Explicit intents explicitly defines the component which should be called by the Android system, by using the Java class as identifier. Intent i = new Intent(this,NewActivity.class); i.putExtra("Value1", "This value one for ActivityTwo "); i.putExtra("Value2", "This value two ActivityTwo"); startActivity(i);
  • 6. Implicit Intents Implicit intents specify the action which should be performed and optionally data which provides data for the action. Intent intent = new Intent(Intent.ACTION_VIEW); intent.sendData(Uri.parse("http://google.com")); startActivity(intent);
  • 7. Using the share intent Lots of Android applications allow you to share some data with other people, e.g. the Facebook, G+, Gmail and Twitter application. You can send data to one of this components.
  • 8. Share Intent Example You can send data to one of this components. Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(android.content.Intent.EXTRA_TEXT, "News for you!"); startActivity(intent);
  • 9. Receive Intent data The component which receives the Intent can use the getIntent().getExtras() method call to get the extra data. Bundle extras = getIntent().getExtras(); if (extras != null) { String value1 = extras.getString(Intent.EXTRA_TEXT); }
  • 10. Intent Filters If an Intents is send to the Android system, it will determine suitable applications for this Intents. If several components have been registered for this type of Intents, Android offers the user the choice to open one of them.
  • 11. Intent Filters An Intent Filter declares the capabilities of a component. It specifies what an activity or service can do and what types of broadcasts a Receiver can handle. It allows the corresponding component to receive Intents of the declared type. IntentFilters are typically defined via the AndroidManifest.xml file
  • 12. Register your Activity as Browser Register an Activity for the Intent which is triggered when someone wants to open a webpage <activity android:name=".BrowserActivitiy" android:label=" @string/app_name"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="http"/> </intent-filter> </activity>
  • 13. Register your Activity for the Share Intent Register an Activity for the ACTION_SEND Intent for the text/plain mime type. <activity android:name=".ActivityTest" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="text/plain" /> </intent-filter> </activity>
  • 14. Workshop: Explicit Intents Create 2 Activities, first activity has a edit text and button after push the button it 'll sent data in edit text to the second activity.
  • 15.
  • 16. Workshop: Implicit Intents Create an app to use a Spinner to select the Intent which should get trigger : ● Open Browser ○ Intent.ACTION_VIEW ○ Uri.parse("http://google.com"); ● Call Someone ○ Intent.ACTION_CALL ○ Uri.parse("tel:0891234567"); ● Dial ○ Intent.ACTION_DIAL ○ Uri.parse("tel:0891234567");
  • 17. Workshop: Implicit Intents ● Show Map ○ Intent.ACTION_VIEW ○ Uri.parse("geo:0,0?q=100.00,15.00"); ● Search on Map ○ Intent.ACTION_VIEW ○ Uri.parse("geo:0,0?q=Bluecup coffee");
  • 18.
  • 19. Workshop: Share Intent Create App with simple share, to share text in edit text to another application. Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, shareText); startActivity(intent);
  • 20.
  • 21. End