Android App Development 07 : Intent & Share
Upcoming SlideShare
Loading in...5
×
 

Android App Development 07 : Intent & Share

on

  • 706 views

 

Statistics

Views

Total Views
706
Views on SlideShare
706
Embed Views
0

Actions

Likes
0
Downloads
22
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Android App Development 07 : Intent & Share Android App Development 07 : Intent & Share Presentation Transcript

  • 7 Intent & Share Anuchit Chalothorn anoochit@gmail.comLicensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  • IntentIntents are asynchronous messages whichallow Android components to requestfunctionality from other components of theAndroid system.Ref: http://developer.android.com/reference/android/content/Intent.html
  • Intent to another activityIntent to the Android system to starts anotheractivityIntent intent = new Intent(this,NewActivity.class);startActivity(intent);
  • Intent with dataAn Intent can contain data. This data can beused by the receiving component. As data itmay send the URL to the browser componentwhich 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 IntentsExplicit intents explicitly defines the componentwhich 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 IntentsImplicit intents specify the action which shouldbe performed and optionally data whichprovides data for the action.Intent intent = new Intent(Intent.ACTION_VIEW);intent.sendData(Uri.parse("http://google.com"));startActivity(intent);
  • Using the share intentLots of Android applications allow you to sharesome data with other people, e.g. theFacebook, G+, Gmail and Twitter application.You can send data to one of this components.
  • Share Intent ExampleYou 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 dataThe component which receives the Intent canuse the getIntent().getExtras() method call toget the extra data.Bundle extras = getIntent().getExtras();if (extras != null) { String value1 = extras.getString(Intent.EXTRA_TEXT);}
  • Intent FiltersIf an Intents is send to the Android system, itwill determine suitable applications for thisIntents. If several components have beenregistered for this type of Intents, Android offersthe user the choice to open one of them.
  • Intent FiltersAn Intent Filter declares the capabilities of acomponent. It specifies what an activity orservice can do and what types of broadcasts aReceiver can handle. It allows thecorresponding component to receive Intents ofthe declared type. IntentFilters are typicallydefined via the AndroidManifest.xml file
  • Register your Activity as BrowserRegister an Activity for the Intent which istriggered when someone wants to open awebpage<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 IntentRegister an Activity for the ACTION_SENDIntent 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 IntentsCreate 2 Activities, first activity has a edit textand button after push the button it ll sent datain edit text to the second activity.
  • Workshop: Implicit IntentsCreate an app to use a Spinner to select theIntent 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 IntentCreate App with simple share, to share text inedit text to another application.Intent intent = new Intent(Intent.ACTION_SEND);intent.setType("text/plain");intent.putExtra(Intent.EXTRA_TEXT, shareText);startActivity(intent);
  • End