IT Community - Software Programming, Web Development and Technical Support

j2me programing with BlackBerry phones -useful tips

This is a discussion on j2me programing with BlackBerry phones -useful tips within the Blackberry forums, part of the Mobile Software Development category; What Is - Global Events and Global Event Listeners A BlackBerry application can notify and communicate with other applications through the ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Mobile Software Development > Blackberry

Register FAQ Members List Calendar Mark Forums Read
  #21 (permalink)  
Old 10-27-2007, 02:35 AM
jeyaprakash.c jeyaprakash.c is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 228
jeyaprakash.c is on a distinguished road
Arrow j2me programing with BlackBerry phones -useful tips

What Is - Global Events and Global Event Listeners

A BlackBerry application can notify and communicate with other applications through the use of GlobalEvents.

GlobalEvents are delivered to every application on the BlackBerry that is implementing a GlobalEventListener. When firing a GlobalEvent, you specify a unique ID that allows the listening application to determine if it is an event that it should act on or ignore. A GlobalEvent can also be used to transport data to the listening application. Not only can you alert the listening application that it needs to do some work, you can send it data it can process. A GlobalEvent can contain two integer variables as well as two objects that are delivered to the listening application.

The sample applications below demonstrate how a GlobalEvent can be used as a mechanism for application-to-application communication. The GlobalEventFiring application fires a GlobalEvent that is received by the GlobalEventListening application. The GlobalEventListening application then fires another acknowledging GlobalEvent that is received by the GlobalEventFiring application, causing a Dialog alert to be displayed. In actual practice it would not be required to acknowledge that a GlobalEvent was received: it is just provided for demonstration purposes.

GlobalEventFiring.java
Code:
/*
 * GlobalEventFiring
 *
 * Fires a GlobalEvent and listens for acknowledgement.
 */

package com.samples.eventFiring;

import net.rim.blackberry.api.mail.*;
import net.rim.blackberry.api.mail.event.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;

class GlobalEventFiring extends UiApplication implements GlobalEventListener
{
    private MainScreen mainScreen;

    public static void main(String args[])
    {
        GlobalEventFiring theApp = new GlobalEventFiring();
        theApp.enterEventDispatcher();
    }

    public GlobalEventFiring()
    {

        mainScreen = new MainScreen();

        //Add this class as a global event listener.
        addGlobalEventListener(this);

        mainScreen.setTitle(new LabelField("Global Event Firing"));

        MenuItem fireEvent = new MenuItem("Fire Global Event", 20, 20)
        {
            public void run()
            {
                //Post the GlobalEvent.
                //Long = com.samples.globalEventFiring.GlobalEventFiring
                ApplicationManager.getApplicationManager().postGlobalEvent(0xba4b84944bb7429eL);
            }
        };

        mainScreen.addMenuItem(fireEvent);
        pushScreen(mainScreen);

    }

    //This method is invoked after a GlobalEvent is fired.
    //This sample does not make use of passing any integer or Object data with the GlobalEvent,
    //but they can be used to convey information between applications.
    public void eventOccurred( long guid, int data0, int data1, Object object0, Object object1)
    {
        //Is this the GlobalEvent we are waiting for?
        //Long = com.samples.globalEventFiring.GlobalEventListening
        if (guid == 0x7d3a74a5ccfe6483L)
        {
            //Yes it is.

            System.out.println("Acknowledgement received.");

            UiApplication.getUiApplication().invokeLater(new Runnable()
            {
                public void run()
                {
                    Dialog.alert("Event was fired and acknowledged.");
                }
            });
        }
    }
}

GlobalEventListening.java

Code:
/*
 * GlobalEventListening
 *
 * Listens for a GlobalEvent and fires back an acknowledgement.
 * This application must be set to auto run at startup.
 */

package com.samples.eventFiring;

import net.rim.blackberry.api.mail.*;
import net.rim.blackberry.api.mail.event.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;

class GlobalEventListening extends UiApplication implements GlobalEventListener
{
    private MainScreen mainScreen;

    public static void main(String args[])
    {
        GlobalEventListening theApp = new GlobalEventListening();
        theApp.enterEventDispatcher();
    }

    public GlobalEventListening()
    {
        //Add this class as a global event listener.
        addGlobalEventListener(this);
    }
    //This method is invoked after a GlobalEvent is fired.
    //This sample does not make use of passing any integer or Object data with the GlobalEvent,
    //but they can be used to convey information between applications.
    public void eventOccurred( long guid, int data0, int data1, Object object0, Object object1)
    {
        //Is this the GlobalEvent we are waiting for?
        //Long = com.samples.globalEventFiring.GlobalEventFiring
        if (guid == 0xba4b84944bb7429eL)
        {
            //Yes it is.
            System.out.println("Event received, sending acknowledgment...");

            //Fire another GlobalEvent to acknowledge to the originating class that
            //it was received. This process is not required, only included for
            //demonstration purposes.
            //Long = com.samples.globalEventFiring.GlobalEventListening
            ApplicationManager.getApplicationManager().postGlobalEvent(0x7d3a74a5ccfe6483L);
        }
    }

}
__________________
thanx n regards
jeyaprakash.c
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #22 (permalink)  
Old 10-27-2007, 02:37 AM
jeyaprakash.c jeyaprakash.c is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 228
jeyaprakash.c is on a distinguished road
Arrow Re: j2me programing with BlackBerry phones -useful tips

What Is - Supported System.getProperty keys

BlackBerry Device Software 3.7 supports the following keys for use in the System.getProperty method:

microedition.encoding
microedition.configuration
microedition.profiles
microedition.platform
microedition.locale
user.timezone

BlackBerry Device Software 4.0 and later supports all keys listed above, as well as the following keys for use in the System.getProperty method:

microedition.jtwi.version
microedition.media.version
supports.mixing
supports.audio.capture
supports.video.capture
supports.recording
microedition.pim.version
__________________
thanx n regards
jeyaprakash.c
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #23 (permalink)  
Old 10-27-2007, 02:40 AM
jeyaprakash.c jeyaprakash.c is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 228
jeyaprakash.c is on a distinguished road
Arrow j2me programing with BlackBerry phones -useful tips

What Is - System Global Events

An application can be notified of certain system events that occur on the BlackBerry device through the use of the net.rim.device.api.system.GlobalEventListener interface. Many of these events have been exposed through other application programming interface (API), but the GlobalEventListener capability provides a direct mechanism for receiving these events. This article provides a list and explanation of many of the global events provided on the BlackBerry Device Software 4.1 that might be useful to third-party developers. It is important to understand that leveraging the GlobalEventListener capability takes additional resources due to the large number of global events that are issued in the system. As such, developers need to be very careful with the implementation of the eventOccurred method to make sure that it is as efficient as possible. Additionally, applications should only register as a GlobalEventListener when running and actively requiring this capability. Applications can also use the GlobalEventListener capability for inter-process communication in their own application. For more information on sending and listening for global events,
Existing Global Events in BlackBerry Device Software 4.1

net.rim.device.api.i18n.DateFormat.GUID_DATE_FORMA T_CHANGED: GUID for the global event sent when the default date format changes.

net.rim.device.api.util.DateTimeUtilities.GUID_DAT E_CHANGED: GUID for the global event sent when the date changes.

net.rim.device.api.util.DateTimeUtilities.GUID_TIM EZONE_CHANGED: GUID for the global event sent when the timezone changes.

net.rim.device.api.i18n.Locale.Locale.GUID_INPUT_L OCALE_CHANGED: GUID for global event sent when the current input locale changes.

net.rim.device.api.i18n.Locale.Locale.GUID_LOCALE_ CHANGED: GUID for global event sent when the current locale changes.

net.rim.device.api.itpolicy.ITPolicy.GUID_IT_POLIC Y_CHANGED: The GUID for the global event sent when the IT Policy changes.

net.rim.device.api.itpolicy.ITPolicy.GUID_IT_POLIC Y_CHANGED_LOCKED_HANDHELD: The GUID for the global event sent when the IT Policy changes and device locking is required.

net.rim.device.api.lowmemory.LowMemoryManager.GUID _FLASH_LOW: The GUID of the global event, posted by the system, to notify the LowMemoryManager that the system is low on memory.

net.rim.device.api.ui.Font.GUID_FONT_CHANGED: The GUID for the global event sent when the system font changes.

net.rim.device.api.servicebook.ServiceBook.GUID_SB _ADDED: The GUID for the global event sent when a service book is added.

net.rim.device.api.servicebook.ServiceBook.GUID_SB _BR_END: The GUID for the global event sent when service book backup-restore ends.

net.rim.device.api.servicebook.ServiceBook.GUID_SB _BR_START: The GUID for the global event sent when service book backup-restore starts.

net.rim.device.api.servicebook.ServiceBook.GUID_SB _CHANGED: The GUID for the global event sent when a service book is changed.

net.rim.device.api.servicebook.ServiceBook.GUID_SB _OTA_SWITCH: The GUID for the global event sent when all service records are inserted due to a move BlackBerry Enterprise Server command OTA.

net.rim.device.api.servicebook.ServiceBook.GUID_SB _OTA_UPDATE: The GUID for the global event sent when all service records are updated for a UID OTA.

net.rim.device.api.servicebook.ServiceBook.GUID_SB _POLICY_CHANGED: The GUID for the global event sent when the service book responds to an IT Policy changed event.

net.rim.device.api.servicebook.ServiceBook.GUID_SB _REMOVED: The GUID for the global event sent when a service book is removed.

net.rim.device.api.io.DatagramStatusListener.GUID_ GME_CRYPTO_FAILURE: The GUID for the global event sent when a decryption error occurs when trying to decrypt the incoming datagram.

Note: GUID stands for Global Unique Identifier.
__________________
thanx n regards
jeyaprakash.c
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #24 (permalink)  
Old 10-27-2007, 02:41 AM
jeyaprakash.c jeyaprakash.c is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 228
jeyaprakash.c is on a distinguished road
Arrow j2me programing with BlackBerry phones -useful tips

What Is - The reason a reset is required when upgrading an application

When performing an application upgrade over the wireless network, the BlackBerry device user may be prompted to restart the BlackBerry device for the upgrade to complete. The application developer has minimal influence over whether or not a reset is required, other than to completely terminate the application prior to performing the upgrade. In general, no action is required from the application developer because these reset prompts are normal for the BlackBerry device and provide a clean operating environment.

The following list provides the most common causes for BlackBerry device reset prompts when upgrading an application:

1. An application thread is running from one of the COD files to be updated.
2. The application defines a dependency between a native class and one of its classes, possibly by a listener.
3. The application contains a live reference to a large array or large String that cannot be copied.
4. The application contains a live reference to a transient object.
5. The application contains a live reference to a persistent object.
6. The virtual machine (VM) detects another application's dependence on one of the application's COD files, possibly by a COD file defined as a library.
7. The application is very large and/or contains many sibling COD files, resulting in the need for some complex linking operations that are only performed during startup.
__________________
thanx n regards
jeyaprakash.c
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #25 (permalink)  
Old 10-27-2007, 02:46 AM
jeyaprakash.c jeyaprakash.c is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 228
jeyaprakash.c is on a distinguished road
Arrow j2me programing with BlackBerry phones -useful tips

How To - Launch a third party application from another third party application

On the handheld, you can launch a third party application from another third party application. The code sample below demonstrates how this can be done.
Code:
int modHandle = CodeModuleManager.getModuleHandle("MyApplication");
ApplicationDescriptor[] apDes = CodeModuleManager.getApplicationDescriptors(modHandle);
ApplicationManager.getApplicationManager().runApplication(apDes[0]);

An application can also schedule another application to be launched at a specific time. This can be done through the use of the ApplicationManager.scheduleApplication method.
__________________
thanx n regards
jeyaprakash.c
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #26 (permalink)  
Old 04-02-2008, 05:08 AM
jeyaprakash.c jeyaprakash.c is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 228
jeyaprakash.c is on a distinguished road
Arrow j2me programing with BlackBerry phones -useful tips

How to - Detect system availability on startup

The best way to ensure that the system is available and ready is to leverage the ApplicationManager class with its inStartup method along with using a system listener and its powerUp method. Sample code is included below as an example on how you can detect when the system is available and ready.
Code:
public static void main( String[] args ) {
   // Perform additional work as part of main method if necessary.
   if( ApplicationManager.getApplicationManager().inStartup() ) {
      // Add a system listener to detect when system is ready and available.
      applicationInstance.addSystemListener( applicationInstance );
   } else {
      // System is already ready and available so perform your start up work
      now.
      // Note that this work must be completed using invokeLater because the
      // application has not yet entered the event dispatcher.
      applicationInstance.doStartupWorkLater();
   }
   // Enter the event dispatcher.
   applicationInstance.enterEventDispatcher();
}
/**
* Implementation of the powerUp method for the SystemListener interface
*
*/
public void powerUp()
{
   applicationInstance.removeSystemListener( this );
   doStartupWork();
}
/**
* Perform the start up work on a new Runnable using the
* invokeLater construct to ensure that it is executed
* after the event thread has been created.
*
*/
private void doStartupWorkLater()
{
   applicationInstance.invokeLater( new Runnable() {
      public void run() {
         doStartupWork();
      }
   } );
}
/**
* Your private method for performing your startup work.
*
*/
private void doStartupWork()
{
   // Perform your start up activities here!
}
__________________
thanx n regards
jeyaprakash.c
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #27 (permalink)  
Old 04-02-2008, 05:09 AM
jeyaprakash.c jeyaprakash.c is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 228
jeyaprakash.c is on a distinguished road
Arrow Re: j2me programing with BlackBerry phones -useful tips

How to - Capture power change events

Your application can be notified when power change events take place on the BlackBerry device. This could be used to halt certain features when the battery power is low, and resume them when it is back to normal levels. Implementing the SystemListener interface (net.rim.device.api.system.SystemListener) can perform these operations. Events such as the BlackBerry powering on, powering off, and changes in the battery state can be captured. The following sample application shows how to implement the SystemListener interface:

Code:
/**
 * PowerChangeEvent.java
 *
 */

import java.util.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;

public class PowerChangeEvent
  extends Application implements SystemListener
{
  public static PowerChangeEvent theApp;

  public static void main(String args[])
  {
    theApp = new PowerChangeEvent();
    theApp.enterEventDispatcher();
  }

  public PowerChangeEvent()
  {
    //Register this instance with the system listener.
    Application.getApplication().addSystemListener(this);
    System.out.println("PowerChangeEvent: PowerChangeEvent has started!");
  }

  //Invoked when the user is putting the device into a power off state.
  public void powerOff()
  {
    System.out.println("PowerChangeEvent: The BlackBerry is powering off.");
  }

  //Invoked when the device has left the power off state.
  public void powerUp()
  {
    System.out.println("PowerChangeEvent: The BlackBerry is powering up.");
  }

  //Invoked when the internal battery voltage falls below a critical level.
  public void batteryLow()
  {
    System.out.println("PowerChangeEvent: The battery is getting low!");
  }

  //Invoked when the internal battery voltage has returned to normal.
  public void batteryGood()
  {
    System.out.println("PowerChangeEvent: The battery level is now good!");
  }

  //Invoked when the internal battery state has changed.
  //Not used in this sample.
  public void batteryStatusChange(int status)
  {
  }
}
__________________
thanx n regards
jeyaprakash.c
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #28 (permalink)  
Old 04-02-2008, 05:25 AM
jeyaprakash.c jeyaprakash.c is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 228
jeyaprakash.c is on a distinguished road
Arrow vibration

we can vibrate a Blackberry mobile using net.rim.device.api.system Package

To Start:
Code:
Alert.startVibrate(time in milliSeconds);
To Stop:
Code:
Alert.stopVibrate();
__________________
thanx n regards
jeyaprakash.c
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/blackberry/4198-j2me-programing-blackberry-phones-useful-tips.html
Posted By For Type Date
I know one thing that is nothing: j2me programing with BlackBerry phones -useful tips - DiscussWeb IT Community - Technical Support and Technology Discussions This thread Refback 03-25-2008 07:31 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
J2ME Tips & Tricks prasannavigneshr J2ME 76 09-29-2008 06:54 AM
blackberry in netbeans amansundar Blackberry 30 04-15-2008 10:58 PM
j2me application in Blackberry amansundar Mobile Software Development 2 12-20-2007 02:22 AM
Tips for j2me-code optimisation jeyaprakash.c J2ME 1 11-10-2007 02:22 AM
j2me programing with motorola phones -useful tips jeyaprakash.c J2ME 10 10-27-2007 12:15 AM


All times are GMT -7. The time now is 09:14 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0