How to Write a BlackBerry Application – Lesson 3: Create shortcuts and more

21 Comments

How to write a BlackBerry application – Lesson 3: Open a webpage, system-wide menu Item, adding an icon and yes/no dialog

This is lesson 3 in a series of BlackBerry application development lessons. These lessons are intended to bring someone with no experience in developing applications for BlackBerry, up to speed with the latest development techniques. It’s easier than you think so try it out!

Before starting, this lesson, make sure you have read Lesson 1 and Lesson 2.

1.      Go into the folder where your BlackBerry Lections.jdw file is
2.      Create a folder there called Lection 3
3.      Open up your JDE and open the Workspace called Lections.jdw
4.      Right-Click on Lections.jdw
5.      Select Create new Project
6.      Name the Project Lection_3 and save it to the Folder \Lection 3
7.      Copy the two files HelloWorld.java and Lesson3Screen.java into the \Lection 3 folder
8.      In the JDE right-click on Lection_3 and add the two files HelloWorld.java and Lesson3Screen.java into the project

In this Lesson, you learn how to open up a webpage with the default BlackBerry browser. You can use that to create your own Website-Shortcuts or Link to your Homepage straight out of your BlackBerry application.

BlackBerry development
 
Another thing you learn in this lesson is how to add your own Menu to the System-Menu! Now you can call up your application or do anything else from everywhere in the System. Make sure that you do not add to many Menus to the System-Menu since that can get very confusing for the user.

BlackBerry application

This is what happens when you call up the Menu from anywhere in the System:

BlackBerry app
 
The third thing you learn is how to add an Icon to your application and how to set the Name for the app.

blackberry app

To add an Icon to the application please do the following:
1. Right-Click on Lection_3 and select Add File to Project
2. Select the file icon.png
3. Right-Click on the newly added file icon.png
4. Click Properties
5. Tick Use as Application Icon
Make sure that the icon you add is about 50×50 pixel and in transparent PNG. I use the software Gimp 2 to edit the icon and to set the transparency.
 
To set a name for the application you created right-click on Lection_3, select Properties, click on the General-Tab and set the Name in the Title field. There you can also edit the Vendor, Version and Description.

BlackBerry app
 
Another small feature is a simple Yes/No Dialog. Here is what it looks like:

blackberry dialog
 
I hope you enjoyed this BlackBerry Development Lesson. Please visit my website at mobileutil.com and follow me on Twitter twitter.com/FabianMH!

Let me know what other topics I should cover in the next Development Lesson!

  • http://twitter.com/iskandar_ahmat/statuses/2676506579 iskandar_ahmat (Iskandar Ahmat

    RT @BlackBerryCool: How to Write a BlackBerry Application – Lesson 3: Create shortcuts and more http://bit.ly/u0JMy

  • Tone

    Is there any way for a tutorial on how to add/subtract/etc numbers? For instance how to take input, manipulate the data usign mathametical operands, and then display? I know it is simple, but cannot for the life of me figure it out.

    Thanks!

  • Tone

    Is there any way for a tutorial on how to add/subtract/etc numbers? For instance how to take input, manipulate the data usign mathametical operands, and then display? I know it is simple, but cannot for the life of me figure it out.

    Thanks!

  • http://www.mobile/ Fabian

    @Tone
    you can do it like that:

    //create new integer
    int i = 83;
    int result = 0;

    result = i * i; //result of 83 * 83

    To get a integer from an EditField you can do the following:

    //first you need to create a new EditField:
    EditField ef = new EditField(“Enter a Number:”,”123″);

    //now, to get the integer from that EditField you do the following:
    int e = Integer.parseInt(ef.getText()); //parsed to Integer
    //make sure that the entered value in the EditField is of type integer

    Now in the ‘e’ Variable you have the value from the Field.
    You can add or subtract it now:

    result = 12313 – e; //the result is 12313 minus the field-entry

    Does it work for you? If not, just post again here!

  • http://www.mobile Fabian

    @Tone
    you can do it like that:

    //create new integer
    int i = 83;
    int result = 0;

    result = i * i; //result of 83 * 83

    To get a integer from an EditField you can do the following:

    //first you need to create a new EditField:
    EditField ef = new EditField(“Enter a Number:”,”123″);

    //now, to get the integer from that EditField you do the following:
    int e = Integer.parseInt(ef.getText()); //parsed to Integer
    //make sure that the entered value in the EditField is of type integer

    Now in the ‘e’ Variable you have the value from the Field.
    You can add or subtract it now:

    result = 12313 – e; //the result is 12313 minus the field-entry

    Does it work for you? If not, just post again here!

  • Tone

    Fabian, that works like a champ! I appreciate the response!
    I have been out of coding for quite a few years, and didn’t have a clue how to do it in Java.

    Thanks again,
    Tone

  • Tone

    Fabian, that works like a champ! I appreciate the response!
    I have been out of coding for quite a few years, and didn’t have a clue how to do it in Java.

    Thanks again,
    Tone

  • Tone

    Fabian, that works like a champ! I appreciate the response!
    I have been out of coding for quite a few years, and didn’t have a clue how to do it in Java.

    Thanks again,
    Tone

  • Scott

    Relative to Tone’s question, how do you specify the Edit Field so that the device knows it should be a numeric entry (i.e. when you click in the field the numeric keyboard is the default presentation for entering values).

  • Scott

    Relative to Tone’s question, how do you specify the Edit Field so that the device knows it should be a numeric entry (i.e. when you click in the field the numeric keyboard is the default presentation for entering values).

  • http://www.pigefolio.com/ Peggy

    I’m looking for someone who does Blackberry application!
    Rite me at peggy.boustany@pigefolio.com (The person have to speek french and be in Montreal )

    Peggy ;p

  • http://www.pigefolio.com/ Peggy

    I’m looking for someone who does Blackberry application!
    Rite me at peggy.boustany@pigefolio.com (The person have to speek french and be in Montreal )

    Peggy ;p

  • http://www.pigefolio.com Peggy

    I’m looking for someone who does Blackberry application!
    Rite me at peggy.boustany@pigefolio.com (The person have to speek french and be in Montreal )

    Peggy ;p

  • Guy

    I love the 3 lessons that you have already given us…is there any chance of getting one that will help interface with a web server…i have a web service i am writing that will relay data back and forth but i just need to know how to access my web server from the BB app

  • Guy

    I love the 3 lessons that you have already given us…is there any chance of getting one that will help interface with a web server…i have a web service i am writing that will relay data back and forth but i just need to know how to access my web server from the BB app

  • Guy

    I love the 3 lessons that you have already given us…is there any chance of getting one that will help interface with a web server…i have a web service i am writing that will relay data back and forth but i just need to know how to access my web server from the BB app

  • http://twitter.com/Bloke28 Adam B

    WE WANT MORE!! :) These three lessons have been a great… already i can make an app that says hello <yourname>, Adds to system menu, emails, and can open links to my paypal donations page…. lol

  • Abelvasquez

    Thanks Fabian, I’m getting error, Cannot access an secure api, is necesary to buy the sign keys?

  • shane

    thanks. i was just wondering if i wanted to add several buttons to go to different websites how would i do it so aswell as having “open google” i would have another one saying “open ebay”?

  • Aniketenngg2

    hi fabian I have difficulty to change image effect from original into sepia and negative can u help me out?
    I have tried hard for it but not able to solve.