Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intents.

Similar presentations


Presentation on theme: "Intents."— Presentation transcript:

1 Intents

2 Fancy pants definition of Intent
A passive data structure holding an abstract description of an operation to be performed or a description of something that has happened and is being announced.

3 Regular pants definition
Intents are asynchronous messages which allow Android components to request functionality from other components of the Android system. Allows developers to leverage the capability of other apps

4 Using Intents Intents are sent to the Android system via the startActivity(). Depending on how the Intent was constructed, the Android system will run an receiver and determine possible components that can be started. If several components have registered for the same intents the user can decide which component should be started.

5 How we’ve used Intents so far
An Intent object is passed to Context.startActivity() or Activity.startActivityForResult() to launch an activity or get an existing activity to do something new. It can also be passed to Activity.setResult() to return information to the activity that called startActivityForResult().

6 Explicit vs Implicit Intents
Explicit intents explicitly define the component which should be called by the Android system by using the Java class as the identifier. Implicit intents specify the action which should be performed and optional data which provides data for the action.

7 Intents Intents can contain Component Name Action Data

8 Intents : Component Name
The name of the component that should handle the intent. The name of the component should be a fully qualified class name of the target component its package name.  Package name Fully Qualified Class Name com.example.project.app.FreneticActivity

9 Intents : Component Name
Explicit Intents need a component name Implicit Intents do NOT need a component name

10 Intent : Action A string naming the action to be performed

11 Intent : Data The data to operate on, such as a person record in the contacts database, expressed as a Uri.

12 Examples of Action/Data pairs
ACTION_VIEW content://contacts/people/1 -- Display information about the person whose identifier is "1". ACTION_DIAL content://contacts/people/1 -- Display the phone dialer with the person filled in. ACTION_VIEW tel:123 -- Display the phone dialer with the given number filled in. Note how the VIEW action does what is considered the most reasonable thing for a particular URI. ACTION_DIAL tel:123 -- Display the phone dialer with the given number filled in. ACTION_EDIT content://contacts/people/1 -- Edit information about the person whose identifier is "1". ACTION_VIEW  Display the browser with the given url filled in.

13 Example Intents : Long Way
Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse(" startActivity(intent);

14 Example Intents : Compact Way
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(" startActivity(intent);

15 Show Phone Number in Dialer App
////Show Phone number in Dialer App Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("tel: ")); startActivity(intent);

16 Google Search ////Open browser and perform a google search Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, "SMU"); startActivity(intent);

17 Open Address in Google Maps
//Open Google Maps and load a map for a specific geo location Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo: , ")); startActivity(intent);

18 Compose an //Compose an with subject and body filled in Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:?subject=" + Uri.encode("Mixed Berry Recipe") + "&body=" + Uri.encode("I found this awesome recipe"))); startActivity(intent);

19 Choose an Activity to share data with
//Send data to any app that accepts text/plain mime type Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, "Subject Here"); intent.putExtra(Intent.EXTRA_TEXT, "Body Here"); //This will create a chooser pop-up that allows the user to select from a list of options for how they //want to handle the intent (which app to use). startActivity(Intent.createChooser(intent, "Share this recipe with")); //Add special text to chooser pop-up

20 Edit Contact //Edit a contact in your contacts list Intent intent = new Intent(Intent.ACTION_EDIT, Uri.parse("content://contacts/people/1")); startActivity(intent);


Download ppt "Intents."

Similar presentations


Ads by Google