1 / 20

Intents

Intents. 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. Regular pants definition.

alissa
Download Presentation

Intents

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Intents

  2. Fancy pants definition of Intent Apassive 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 toContext.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_VIEWcontent://contacts/people/1 -- Display information about the person whose identifier is "1". • ACTION_DIALcontent://contacts/people/1 -- Display the phone dialer with the person filled in. • ACTION_VIEWtel: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_DIALtel:123 -- Display the phone dialer with the given number filled in. • ACTION_EDITcontent://contacts/people/1 -- Edit information about the person whose identifier is "1". • ACTION_VIEWhttp://www.google.com -- 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("http://www.smu.edu")); startActivity(intent);

  14. Example Intents : Compact Way Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); 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:2147681234")); 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:32.84453,-96.78534")); startActivity(intent);

  18. Compose an Email //Compose an email 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);

More Related