How to write a BlackBerry application – Lesson 2: Mail API, Invoke API, Menu

20 Comments

How to write your second BlackBerry application – Lesson 2: Mail API, Invoke API, Menu

In the first tutorial you learned how to set up the BlackBerry JDK (Java Development Kit) and how to create a simple User Interface with Buttons, Labels and Edit Fields.

In this lesson, you’ll learn how one can program, create and compose email messages as well as how to add a MenuItem to your application.

1. You open up the JDE (Java Development Environment) and load your Workspace file. Go to File -> Recent Workspaces to load up the Lections.jdw file.
2. Now right-click on Lections.jdw and select Create new Project
3. Name it Lection_2
4. Now right-click on Lection_2 and select Add file to Project
5. Select both files HelloWorld.java and Lesson2Screen.java to import them into the project
6. You now have the project set up and are ready to jump into the code

What the application allows you to do is the following:

It gives you 3 EditFields where you can enter data. It also provides you with 2 ButtonFields.

The one button is called Create email and when you click that button it pops up a new email message with the data you entered in the fields. From there, you can send the email.

BlackBerry development article 2

The other button is called Send email and after you click the button, it sends off the email straight from your app without showing the form where you can still edit the message. Then, when you go into your Messages Application you find the sent mail there.

BlackBerry development

What else do I learn in this lesson?

You learn how to insert colored fields into the screen and you learn how to add a MenuItem to your app.

BlackBerry development

What else is there to know about this lesson?

We imported two new APIs into our project:

import net.rim.blackberry.api.invoke.*;
import net.rim.blackberry.api.mail.*;

The invoke-API is needed to invoke the Messages application to pop up that email form and the mail-API is needed to send of the email from the Send email button. For a complete list of all APIs you can go to Help -> API Reference.

Is there anything specific you want me to cover in the next lesson?

Drop your thoughts in the comments or reply to me on Twitter: www.twitter.com/FabianMH.

  • akhan

    nice review.

    any thing planned for different kind of views/gui designs and/or communication with web services to get data and display it more cleanly?

    thanks.

  • akhan

    nice review.

    any thing planned for different kind of views/gui designs and/or communication with web services to get data and display it more cleanly?

    thanks.

  • akhan

    nice review.

    any thing planned for different kind of views/gui designs and/or communication with web services to get data and display it more cleanly?

    thanks.

  • Sean

    Nice review i’m enjoying the lessons thanks keep them going. Can you make your own themes using what was shown in these lessons?

  • Sean

    Nice review i’m enjoying the lessons thanks keep them going. Can you make your own themes using what was shown in these lessons?

  • Jacy

    How did you invoke the messages application? using the Invoke class? Because i tried that, and the “Save Drafts” command does not seem to work. Did you experience this?

  • Jacy

    How did you invoke the messages application? using the Invoke class? Because i tried that, and the “Save Drafts” command does not seem to work. Did you experience this?

  • Marius

    ~~~~~~~~~~~~~~~~~~~~~~
    There is a typo (I’m surprised no one mentioned it)

    In helloworld.java file, it should be new Lesson2Screen not Lesson3Screen

    Also, if youre trying this on the simulator, it does not pop up with the 2nd screen after clicking (send Email) … might only work for the live phone?
    ~~~~~~~~~~

  • http://~ Marius

    ~~~~~~~~~~~~~~~~~~~~~~
    There is a typo (I’m surprised no one mentioned it)

    In helloworld.java file, it should be new Lesson2Screen not Lesson3Screen

    Also, if youre trying this on the simulator, it does not pop up with the 2nd screen after clicking (send Email) … might only work for the live phone?
    ~~~~~~~~~~

  • Marco Faustinelli

    Like lesson1, this one is inaccurate too. Is this app not meant for the sim? And what is that Invoke.invokeApplication() thing? Looks like some basic info to me! Reading from the comments, nobody got this up & working.

  • Marco Faustinelli

    Like lesson1, this one is inaccurate too. Is this app not meant for the sim? And what is that Invoke.invokeApplication() thing? Looks like some basic info to me! Reading from the comments, nobody got this up & working.

  • Mr Bananaplan

    test

  • Mr Bananaplan

    test

  • Mr Bananaplan

    yes,there is something wrong in Lesson2Screen.
    I found that navigationClick() can not be invoked.So you need to setChangeListener for btnSubmit and btnSend,and then put the send email code into fieldChanged().

  • Guest

    invalid method declaration; return type required (Lesson2Screen Function)

  • Krrrr

    puto

  • Krrrr

    puto

  • Krrrr

    puto

  • Allen

    do write an app for using telephony services like call blocking,auto answer,recording etc.

  • Aniketenngg2

    can you put a lesson on image processing i.e changing image effects like emboss,negative,grayscale etc…and changing hue,saturation,brightness etc
    that will help me and other BB developers….

    thanks