Android Topics 1 Add email to the Coffee

  • Slides: 3
Download presentation
Android Topics 1. Add email to the Coffee Ordering App

Android Topics 1. Add email to the Coffee Ordering App

Objectives • In this in-class coding app, you will use an intent to send

Objectives • In this in-class coding app, you will use an intent to send an order summary to an email app. You should already have taken some time to experiment with writing code for different intents listed in the Common Intents guide. TIP: If you have no idea how to accomplish this: 1. Research the common intents guide from the official Android Documentation. This site is very helpful for showing you how to send an intent to compose an email with optional attachments. 2. Do a web search. Look at Stack Overflow posts and tutorials.

T a s k s • Create a new intent object and pass the

T a s k s • Create a new intent object and pass the Intent. ACTION_SENDTO argument. • Set the data to be a URI of this format, "mailto: ", that way all the email apps will handle this intent. • Add some extra data into the intent. Specify the subject of the e-mail message. Add the person’s name. • Add the necessary intent extras for each additional piece of information you want to provide about the email. For example, a. b. c. d. intent extra about the recipients of the email Intent. EXTRA about the subject line of the email. Intent. EXTRA to specify the body of the email. Intent. EXTRA_TEXT is a constant defined in the intent java class as a string in the intent class. Populate this extra, containing the body of the email message. • When the email app receives the intent, it will know to check for this intent extra to find the body of email and then it can populate that. The body of the email is the order summary. • Check if there's an activity on the device to handle this intent. If there is then it's safe to send the intent and recall start activity using this intent. If there's no activity on the device to handle the intent, then we skip this block of code and we skip sending the intent. • Run the app on our device. Now when I click on the order button, it sends an intent to an email app on the device. By default, the Gmail app is going to handle this intent.