Friday, February 3, 2012

Splash Screen

Kebiasaan sebuah aplikasi entah itu aplikasi yang berbasi java  atau lainnya, menggunakan splash screen sebagai tampilan pertama untuk memperlihatkan logo atau pengenalan sebuah aplikasi, dalam tutorial ini saya akan coba jelaskan proses pembuatan splash screen pada aplikasi blackberry.

Contoh detail script splash screen :
package mainapp;
import java.util.Timer;
import java.util.TimerTask;
import utils.AnimatedGIFField;
import utils.GraphicUtil;
import net.rim.device.api.notification.NotificationsConstants;
import net.rim.device.api.notification.NotificationsManager;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.system.GIFEncodedImage;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
public final class SplashScreen extends MainScreen
private int _width;
private int _height;
private Bitmap splashImage;
private int offsetY;
private GIFEncodedImage _waitImage;
private AnimatedGIFField _waitField;
private int offsetYWait;
    public SplashScreen()
EncodedImage backgroundImage = EncodedImage.getEncodedImageResource(Const.splasScreenImage);
     _waitImage = Const.getLargeLoadAnimation();
     SplashManager manager = new SplashManager(0);
     _waitField = new AnimatedGIFField(_waitImage);
     _width = Display.getWidth();
     _height = Display.getHeight();
int ratiow = 100 * _width / backgroundImage.getWidth();
int desiredHeight = backgroundImage.getHeight() * ratiow / 100;
     splashImage = GraphicUtil.resizeBitmap(backgroundImage, _width, desiredHeight);
     offsetY = (_height - splashImage.getHeight()) >> 1;
     int splashY = _height - (_height / 4);
        offsetYWait = splashY - (_waitField.getHeight() / 2); 
     final Timer timer = new Timer();
     TimerTask tt = new TimerTask(){
 public void run() {
  UiApplication.getUiApplication().invokeLater(new Runnable() { 
     public void run(){
     UiApplication.getUiApplication().pushScreen(new Login());
timer.schedule(tt, 3000, 3000);
Object theSource = new Object() {
public String toString() {
return Const.nulinesProfileName;
theSource, NotificationsConstants.IMPORTANT);
    private final class SplashManager extends Manager 
public SplashManager(long style)
protected void paintBackground(Graphics graphics)
graphics.fillRect(0, 0, _width, _height);
if (splashImage != null){
graphics.drawBitmap(0, offsetY, splashImage.getWidth(), splashImage.getHeight(), splashImage, 0, 0);
protected void sublayout(int width, int height) {
layoutChild(_waitField, width, height);
setPositionChild(_waitField, (width - _waitField.getWidth()) >> 1, offsetYWait);
setExtent(Display.getWidth(), Display.getHeight());

Supported Media Types on BlackBerry Smartphones

In the Media application on the BlackBerry® smartphone, you can open media files such as videos, ring tones, pictures, and songs that are stored on the BlackBerry smartphone built-in media storage, application storage, or on a media card.
The following tables list the codecs that are recommended and the codecs that are supported for video formats and audio formats on BlackBerry smartphones, as well as whether RTSP streaming is supported using that file format.

C10 Audio And Video Playback

This tutorial will show you how to play audio and video files in your application. I will show you how to use the Mobile Media API (MMAPI), also known as JSR 135 on BlackBerry SmartPhones.
I will guide you through the MMAPI, then show you on example on how to play simple tunes, how to play music from file bundled with the application, and how to play the file from your SD card.
I will also tell you which files are supported and how to implement PlayerListener to track events like when the song has finished.
Then we will cover the video playback. I will show you how to play video in full screen and non-full screen modes.

Audio Playback

To play audio on BlackBerry SmartPhones, we will use classes and interfaces from the package. This package is fully compatible with the MMAPI (JSR 135) and if you already have knowledge on how to use it, you can start using it straight away.
Let’s start with an overview of the Manager class.

Manager Class

If you did not notice already there are two classes called Manager in the BlackBerry APIs. The first class is called and the other one is net.rim.device.api.ui.Manager. The first one is the one used for media handling and the latter one is used for managing the UI components of the screen. It is worth paying attention when importing packages.
The Manager class was introduced in version 4.0.0 of BlackBerry JDE. We need the Manager to get access to system resources such as the Player for multimedia processing.
So first thing the Manager does is create a Player which we use to play our media files.
But it can also be used to query a Player, what controls it supports, i.e. volume controls as well as supported content types and protocols. It can be also used to play single tones.

Content Types and Protocols

Content types indentify the type of media. They are also registered as MIME types.
Common audio content types are:
Wave audio files: audio/x-wav, usually files with extension .wav
MP3 audio files: audio/mpeg, usually files with extension .mp3
MIDI audio files: audio/midi, usually files with extension .midi
To find our which protocols specific content types support on the device we can use:
public static String[] getSupportedProtocols(String content_type).

You can also use:
public static String[] getSupportedContentTypes(String protocol),

to find out which content types specific protocols support.

Playing Single Tones

To play a single tone you can use:
public static void playTone(int note, int duration, int volume)
throws MediaException
• SEMITONE_CONST = 17.31234049066755 = 1/(ln(2^(1/12)))
• note = ln(freq/8.176)*SEMITONE_CONST
• The musical note A = MIDI note 69 (0x45) = 440 Hz
• duration is note duration in milliseconds, and
• volume is in range from 0 to 100.
We can use ToneControl constants to play a single note to make our life a little bit easier:
try {
Manager.playTone(ToneControl.C4, 1000, 100);
} catch (MediaException e) { }
This will play middle C note for 1 second at full volume.

Creating a Player

To create a player which will play our audio files we use the following:
Player Manager.createPlayer(String url);
Where url is the location of the audio file. It can be bundled with the application or located on the
device’s memory or SD card.

Player Class

Player has a life cycle. It has 5 states: unrealized, realized, prefetched, started and closed.
Once you create a player it is in the unrealized state. Once it is created it tries to connect to the source of the audio. When the system finds the source (which can be time consuming – especially when using the network) it moves the player in realized state.
The Prefetched state is when the player is ready to play audio. From start the player and it enters the end it will move back to the prefetched state. It is important to know you cannot call some methods in some states. It makes no sense for example to call method start(); to start playback unrealized, realized or closed state. 
methods which we can call to get from one state into another.

Playing Audio

To play audio in your application you might first want to choose which format to use. For background instrumental music, MIDI is the best format as the file sizes are very small, typically 10 - 20 kb, and the sound quality is very good. However if you want to have vocals, or just voice, or any other sound effects, such as thunder or explosions, you will probably choose Mp3.
Mp3 files are bigger, but you can reduce sample rates, to create smaller files, at cost of quality.
Here is a code sample which opens a midi file called test.mid:
public Player myPlayer;
public VolumeControl vc;.

BlackBerry Java Application Multimedia

Working with multimedia in a BlackBerry device application
Creating a BlackBerry device application that plays media

You can create a BlackBerry® device application that plays media in the BlackBerry® Browser or in the Media application on a BlackBerry device. A BlackBerry device media application can also be created to play audio, video, and binary SVG content. A BlackBerry device application can also be created to record audio and video, and send audio to a Bluetooth® enabled headset.

The Content Handler API, is also used to provide an execution model for remotely invoking non-core BlackBerry device applications. CHAPI is an ideal mechanism for setting invocation parameters for non-core BlackBerry device applications. Using CHAPI, you can invoke applications by providing either a URL, content type, or content ID when using one of the constructors available in javax.microedition.content.Invocation class.

You can create a BlackBerry device application to play media that uses the Player interface and the package. The Player interface has been implemented by RIM. It provides the methods needed to manage the different states of a BlackBerry device application that plays media and control the playback of media files.
A Player object is first constructed in an UNREALIZED state. While in this state the object is incapable of doing anything for lack of information and resources.

Invoking realize() will move the Player into a REALIZED state. This enables the Player to locate information to get the basic resources to play a media file.

Invoking prefetch() will move the Player into a PREFETCHED state. In this state the Player obtains necessary resources, and then “fetches” some of the media file to immediately start playback as soon as the Player has been started.
Invoking start() will move the Player into a STARTED start where the Player starts immediate playback of media.

It is possible to invoke start() without invoking realize() and prefetch(). The start() method will invoke prefetch
(0), which invokes realize() before media playback can be started. The simplicity of using start() in this manner may be offset through increased delays starting media playback.
Create a BlackBerry device application that plays media

  1. Import the required classes.
 and more... click this link to get more explanation

Multimedia Development Guide

BlackBerry Applications and multimedia

You can create a BlackBerry® Application that plays media in the BlackBerry® Browser, or plays media in the media application on the BlackBerry smartphone. You can also create a BlackBerry Application that is a media application. You can create a BlackBerry Application that is a media application and plays binary SVG content. You can create an application that records audio or sends audio to a Bluetooth® enabled headset.
For more information about media types that the BlackBerry smartphone supports, visit to read knowledge base article KB05482.

Using audio and video in a BlackBerry Application

Accessing stored media

You can create a BlackBerry® Application that uses the Connector class and FileConnection interface to access media stored on the BlackBerry smartphone or a microSD card.
Access media on a BlackBerry smartphone
Invoke Pass the following parameters: the file protocol and the location of the media file on the BlackBerry® smartphone.
 FileConnection fconn = (FileConnection)"file:///store/home/user/audio/newfile.mp3");

Access media on a microSD card
Invoke Pass the following parameters: the file protocol and the location of the media file on the microSD card.
 FileConnection fconn = (FileConnection)"file:///SDCard/music/newfile.mp3");

Playing media in the BlackBerry Browser

A BlackBerry® Application can use the methods of the Browser class and BrowserSession class to play media in the BlackBerry® Browser.

Play audio in the BlackBerry Browser
Invoke Browser.getDefaultSession().
BrowserSession soundclip = Browser.getDefaultSession();
Invoke BrowserSession.displaypage().
 Play a video in the BlackBerry Browser
Invoke Browser.getDefaultSession().
BrowserSession soundclip = Browser.getDefaultSession();
Invoke BrowserSession.displaypage().
 Playing media in the media application

On the BlackBerry® smartphones that include the media application, a BlackBerry Application can use the javax.microedition.content and net.rim.device.api.content packages to start the media application with or without content.

Start the media application with or without content
  1. Import the javax.microedition.content package into your application code. Import javax.microedition.content;
  2. Invoke Registry.getRegistry(). Pass the following parameter: the classname parameter which is the name of the class in the application that extends javax.microedition.midlet.MIDletnet.rim.device.api.system.Application, or net.rim.device.api.ui.UiApplication. Store a reference to the returned object in a Registry object. Registry reg = Registry.getRegistry(String classname);
and more... click this link to get more explanation

Thursday, February 2, 2012

Unlock the secrets of advanced BlackBerry development

Advanced APIs

The best BlackBerry apps take advantage of the rich set of advanced APIs available on

this platform. The chapters in Part 1 describe some of the most exciting and compelling features available to you. Chapter 1 provides a crash course in building a variety of RIM applications that can access the local filesystem and the Internet. From there, learn how to use the device to shoot photos, record sound and video, and use the captured data in your app. Next, see the wide variety of options available for playing video, animations, and audio content. Connect the BlackBerry to the rest of the mobile world with wireless messaging and email technologies. Finally, incorporate today’s techniques for safeguarding data into your own applications.

Getting Started

Welcome to the wonderful world of BlackBerry app development! Chapter 1 is intended to get you up to speed as quickly as possible, so you can get right into the good stuff, and it assumes no previous knowledge other than a basic grasp of Java. This chapter will walk you through downloading software, setting up your environment, and then give you a quick tour through the basics of BlackBerry app development. You may linger, skim, or skip ahead as your patience demands.

Initial Setup

As with any new language or platform, you will need to install some new software and set up your computer appropriately. There are many different ways to run a successful BlackBerry project. RIM supports only Windows development, but it has done a good job of releasing tools that enable development on a variety of configurations. This section will focus on what I have found to be the simplest and most effective setup for independent development, with occasional notes for alternative choices you might consider.

Getting Java

You will be developing in Java for the BlackBerry, but before we get that far, we need to make sure Java on your desktop is running properly. RIM uses Java for their toolchain—the set of programs that will convert our application source files into a format that can run on the mobile device. Additionally, our Eclipse IDE requires a Java runtime environment.

To see if Java is installed, open a command prompt. You can do this by clicking Start ➞Run, typing cmd, and pressing enter. A black-and-white command prompt window will appear. Type java -version. You should see something like the following:

java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)

The specific version number isn’t important, just getting a response. If Java is not installed or is not configured correctly, you will see an error like the following:

'java' is not recognized as an internal or external command,
operable program or batch file.

To install Java, go to and look for the Java SE download. You only need to install the Java Runtime Environment (JRE). However, if you plan on doing other Java development besides BlackBerry, you can download the full Java Development Kit (JDK), which also includes the JRE.
Tip: When installing any development software, I suggest you pick an install path that has no spaces in it. For example, instead of installing to c:\Program Files\Java, install to c:\dev\java. This will save you time in the future, as some Java programs and other useful utilities have a hard time working with files that have spaces in their name. Follow this rule for all the other downloads in this chapter, as well.
Once you have downloaded and installed the JRE, try opening another command prompt and typing java -version again. If it still doesn’t recognize the command, you probably need to add Java to your PATH environment variable. In Windows XP, you can access this by right-clicking on My Computer, selecting Properties, clicking the Advanced tab, and then clicking Environment Variables. Make sure the path to your installed java.exe directory is included in the PATH. This will probably be something like c:\dev\java\jre1.6.0_14\bin.

Goldilocks and the Three IDEs

Once upon a time, a developer was evaluating which IDE to use when writing BlackBerry
apps. First she tried the RIM JDE. “Oh my!” she exclaimed. “This IDE is much too ugly!”
Then she tried Netbeans. “This IDE doesn’t understand BlackBerry,” she complained.
Finally, she installed Eclipse with the BlackBerry Plug-in. “Ahhh,” she smiled. “This IDE
is just right!”

The reality is that you can develop in any IDE that you want. The question is how much time and effort you will invest in getting everything to work right. I’ve found that Eclipse is the best platform for doing serious development, and it has only gotten better and easier since RIM released their official Plug-in. I will be using Eclipse for my examples in the rest of this book, and I recommend installing it unless you are already doing BlackBerry development in another environment.

To get started, go to I suggest you download a recent release of the Eclipse IDE for Java EE Developers. Depending on what other kinds of development you do, you may choose to use another package. This is fine, but Eclipse EE contains the most options and will give you the greatest flexibility.

Caution: As of this writing, there are compatibility issues with Eclipse 3.5 (Galileo) and the
BlackBerry JDE Plug-in for Eclipse. If you experience problems, use the older 3.4 (Ganymede)
version of Eclipse. This is currently located in the Downloads page of the Eclipse web site,
where you can select ‘‘Older Versions.’’ You can safely install multiple versions of Eclipse into
separate directories on your computer.
Eclipse doesn’t have a standard Windows installer. Instead, you simply unzip it to a folder on your computer. You could put it somewhere like c:\dev\eclipse. To make it easier to launch, you can right-click and drag the eclipse.exe icon to your desktop or task bar in order to create a shortcut.

When you first launch Eclipse, it will ask you to choose a workspace. You can create one wherever you like. Do not check the option for “Use this as the default and do not ask me again.” One quirk of BlackBerry development is that each BlackBerry app you develop will require its own separate workspace, so you will be switching workspaces as you go through this book.

Plugged In

I have been a fan of Eclipse for many years now, in large part because of its very flexible and powerful Plug-in system. Plug-ins allow developers to tune their workspace for their specific tasks, without needing the bother of relearning a new tool for each new task.

There are currently two ways to install the Plug-in. The first is to go to BlackBerry’s developer web page (currently located at and download the Plug-in as an EXE file. This is the simplest approach, as you can simply download the large file, run it, and then restart Eclipse.

The other way to install the Plug-in is directly through Eclipse. I recommend taking this approach, as it allows you more control over what you install and provides a better way to get updates.

In Eclipse, click the Help menu, then Software Updates. Click the Available Software tab, then click Add site. For the location, enter The BlackBerry Update Site will display. Several options are available. At a minimum, you will need to select the BlackBerry JDE Plug-in for Eclipse and at least one BlackBerry Component Pack.
Note: You may be asked to enter a user name and password. You can register for a free
developer account on the BlackBerry web site if you have not already done so. This prompt
may appear multiple times, so continue entering the account name and password until it goes
away. The servers hosting the Plug-in are sometimes temperamental and will fail with
unhelpful messages; other times, the installation may appear to hang when it is actually
progressing. If you cannot install through Software Updates, you can try again later, or install
the EXE file directly as described above.
If you have a particular BlackBerry device in mind, pick the Component Pack that matches the software version of that device. All these files are very large, so you should probably only start with a few even if you know you will eventually want more.
Tip: You can find the software version on your BlackBerry by selecting Options, and then About. It should be a value like ‘‘’’. When selecting a component pack, only the first two numbers are important. The rest will be used to select an appropriate simulator.
 You should restart Eclipse once the install is complete. After it restarts, you will see a new BlackBerry menu option at the top. You will also have access to two new debug configurations: BlackBerry Device and BlackBerry Simulator. Figure 1-1 shows what your Eclipse environment should look like once you have installed the Plug-in and started a new project.

BlackBerry Programs

If you are developing for a personal BlackBerry device, you probably already have the BlackBerry Desktop Manager and the BlackBerry Device Manager installed. If not, installing them is very easy. Go to and look for the “Desktop Software” download. You may need to select your provider and download the appropriate version for them. You will need to fill out a short form with your name and contact information. Run the downloaded setup file. You may be prompted to install additional software, such as the .NET Framework runtime. Once it’s complete, reboot your computer if prompted. The next time you connect your BlackBerry device to the computer, Windows should automatically install the drivers to access it.
You can launch the BlackBerry Desktop Manager by going to your Start menu and looking under BlackBerry. Depending on your installation choices, the manager may automatically start when you log in to Windows. Figure 1-2 shows the BlackBerry Desktop Manager running.
Simulator Files

Downloading the proper simulator files for the devices you plan to run on is essential, because different types of devices will have different screen sizes and input modes. Even if you have two devices with the same model number, they will behave differently depending on what software version they are running. Simulators are not just important for testing on the computer, though. They also contain essential information for debugging on the actual device.

If you have the physical device you will be using, find the device software version by visiting Options, then About. You will be looking for a version that matches all parts of the version number. For example, if your device has version, only use, not another version that starts with 4.5.0. You can download simulator packs from the BlackBerry web site. The exact location will change, so your best bet is to visit the
Developers page and look around for the BlackBerry Smartphone Simulators. You will see many, many choices. Pick the one that matches your exact version number and device model and, if applicable, carrier. You’ll need to click through another web form—get used to it, as there is no way to save your information. Download the simulator file, then run it to install. You can install to any directory you like.

To switch to using a new simulator in Eclipse, follow these steps, and restart Eclipse if you are ever prompted to do so.

  1. Click the Window menu, then Preferences.
  2. Expand the BlackBerry JDE menu and select Installed Components.
  3. From the drop-down list, select the component pack that corresponds to your device version. For example, pick 4.5 for a device with version If you don’t see your component pack listed, install it following the instructions in the section titled “Plugged In” earlier in this chapter.
  4. Click the MDS Simulator option and navigate to the MDS directory that matches the component pack from Step 3.
  5. Click OK. If you already have a project in Eclipse, you will be prompted to rebuild it.
  6. Click Run, then Debug Configurations.
  7. Create a new BlackBerry Simulator configuration.
  8. Click the Simulator tab.
  9. From the Profile drop-down, select the item that corresponds to the simulator you installed.
You will now be able to use your device’s proper simulator, and you will have access to high-quality on-device debugging.

The Keys to Development

So far, you have installed everything you need to get started writing BlackBerry software. There’s a catch, though: RIM has marked some of their APIs as restricted, and if your program uses any of these APIs, it will not run on the device unless it has been code signed.

Code signing is covered in more detail in Chapter 9. For now, just be aware that this is often a necessary step in development. It can take from a few days to a few weeks to receive code signing keys, so start this early.

You apply for the keys from the BlackBerry developer web site. Once again, you will need to fill out a form with information. As part of the form, you will be asked for an email address. Be aware that RIM will send multiple emails to this address every time you sign an application. Also, keep in mind that you must sign an application every time you make a change and load it on the device. It isn’t unusual for a large RIM app to generate 50 or more emails on a single signing. Therefore, I strongly urge you to enter an unmonitored email address here, or one where you can automatically delete emails from the signing server. If you use your personal email address instead, it will make your life miserable.

The form also includes a question about Certicom cryptography keys. Certicom cryptography is covered in more detail Chapter 5; for now, you can just say “No” here. You should also pick a unique 10-digit PIN. There is a nominal charge for receiving code signing keys, currently $20. You will need one set of keys for each computer you will use for development. The RIM servers sometimes have problems; if you aren’t able to
complete your order online, you can choose to fax it in instead.

Eventually, you should receive an email from RIM with three key files and instruction on installation. Follow the email instructions. If you run into problems during your installation, follow the links in the email for more support. Once you have installed and registered the keys, you will be all set. You have a limited number of signatures, but the limit is absurdly high, so you don’t need to worry about ever running out.

You will initially install the signing keys for a particular version of BlackBerry device software, such as 4.5 or 6.1. At first, you will only be able to sign applications built for that particular device type. There are two fixes for this, though: first, you can safely use an old version of the RIM signing tool on newer versions of device software. In other words, you can use the 4.5 signing tool on builds for 6.1, but not vice versa. Second, you can copy the files SignatureTool.jar, sigtool.db, sigtool.set, and sigtool.csk from one version of the desktop software to another. This also works to sign applications using both the BlackBerry Eclipse Plug-in and another environment on the same computer.

Tip: If you installed the BlackBerry Plug-in, your SignatureTool should be located in a directory like C:\dev\eclipse\plugins\net.rim.eide.componentpack4.5.0_4.5.0.16\components\bin.
That’s it for setup! You now have all the tools you will need to write, debug, and install your own BlackBerry apps.

and more ... click this download link to get full explanation