Android Tutorial Part IV – Email Intent – UAT Tester App

This is the last part of the UAT tester app tutorial for Android. In case you have missed the previous Tutorial click on the links below.

Android Tutorial Part I – Setting the layout
Android Tutorial Part II – Setting the reference variables
Android Tutorial Part III – Pick Gallery Image

In this last tutorial will we set the email intent, meaning that the user can pass the information of the UAT tester app to an installed email-client and send the information to for example the Test Manager. 

Elements of this Email Intent are:

  1. A send button which launch the option to open the email clients
  2. The composition of the email message
  3. Actual email intent structure.

First we start with creating the button (Send defect):

btnsend.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

}

Now that we have set the reference to the button (btnsend) we need to tell the OnClick method what to do when a user clicks this button.

First we will compose the email-message. We will get all the information from the TextViews which we have set in tutorial II.

String esoftwarebrand = tvsoftwarebrand.getText().toString();

String edevicebrand = tvdevicebrand.getText().toString();

String emodeltype = tvmodeltype.getText().toString();

String eandroidversion = tvandroidversion.getText().toString();

String etimestamp = tvtimestamp.getText().toString();

String escreensize = tvscreensize.getText().toString();

String epriolist = priolist.getSelectedItem().toString();

String eexpected = etexpected.getText().toString();

String eactual = etactual.getText().toString();

String ecomments = etcomments.getText().toString();

 

We combine all these strings (content from the TextViews) into an email message:

String emailbody =
("Hi"+ "n"+"n" + "Please see below my test result, I have sent this via the UAT Tester App:" +
"n"+"n" + esoftwarebrand + "n"+ edevicebrand +"n"+ emodeltype + "n"+ eandroidversion +"n"+ etimestamp + "n"+ escreensize + "n"+ "Defect Priority: "+ epriolist + "n"+ "n"+ "The expected result is: "+ "n"+"n" + eexpected + "n"+"n"+ "The actual result is: " + "n"+"n" + eactual + "n"+"n"+ "Extra comment(s): " + ecomments + "n"+"n"+"n"+ "Best Regards"+ "n"+"n"+"n"+ "Download the UAT Tester app via http://bit.ly/QQI4Ge");

So now we have composed the actual email body text which we want to send via email to for example a Test Manager.
The last part is that we want to start the email intent.

First, we create a new Intent via Intent.ACTION_SEND, we can create via INTENT_SUBJECT and INTENT_TEXT the subject line and insert the above email-body we have created.

I have included and IF Statement in case the user decides not to include a screenshot. So the email intent works also without an attached screenshot.

Finally we launch the Email Intent via StartActivity.

Intent email = new Intent (Intent.ACTION_SEND);

email.setType("message/rfc822");

email.putExtra(Intent.EXTRA_SUBJECT, "Defect Raised through: UAT Tester App");

email.putExtra(Intent.EXTRA_TEXT, emailbody);

if(targetUri != null){

email.putExtra(Intent.EXTRA_STREAM, targetUri);

}

startActivity(Intent.createChooser(email, "Choose an Email application:"));

}

});

The complete code would now look like this:

btnsend.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String esoftwarebrand = tvsoftwarebrand.getText().toString();

String edevicebrand = tvdevicebrand.getText().toString();

String emodeltype = tvmodeltype.getText().toString();

String eandroidversion = tvandroidversion.getText().toString();

String etimestamp = tvtimestamp.getText().toString();

String escreensize = tvscreensize.getText().toString();

String epriolist = priolist.getSelectedItem().toString();

String eexpected = etexpected.getText().toString();

String eactual = etactual.getText().toString();

String ecomments = etcomments.getText().toString();

String emailbody = ("Hi"+ "n"+"n" + "Please see below my test result, I have sent this via the UAT Tester App:" +

"n"+"n" + esoftwarebrand + "n"+ edevicebrand +"n"+ emodeltype + "n"+ eandroidversion +"n"+ etimestamp +

"n"+ escreensize + "n"+ "Defect Priority: "+ epriolist + "n"+ "n"+ "The expected result is: "+ "n"+"n" + eexpected + "n"+"n"+ "The actual result is: " + "n"+"n" + eactual + "n"+"n"+ "Extra comment(s): " + ecomments + "n"+"n"+"n"+ "Best Regards"+ "n"+"n"+"n"+ "Download the UAT Tester app via http://bit.ly/QQI4Ge");

Intent email = new Intent (Intent.ACTION_SEND);

email.setType("message/rfc822");

email.putExtra(Intent.EXTRA_SUBJECT, "Defect Raised through: UAT Tester App");

email.putExtra(Intent.EXTRA_TEXT, emailbody);

if(targetUri != null){

email.putExtra(Intent.EXTRA_STREAM, targetUri);

}

startActivity(Intent.createChooser(email, "Choose an Email application:"));

}

});

You can download the app via:

 

1 Response

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*