Wednesday, September 30, 2009

how to detect application is in foreground

net.rim.device.api.system.Application



void
activate()
Handles foregrounding event.

Friday, September 25, 2009

iPhone development short cuts

Reorienting the screen. With the Hello World application running, you can
reorient the Simulator using Command-Left arrow and Command-Right arrow.
n Going home. Tap the Home button (Command-Shift-H) to leave the application
and return to the SpringBoard home screen.
n Locking the “phone.” Hardware, Lock (Command-L) simulates locking the
phone.
n Viewing the console. In Xcode, choose Run, Console (Command-Shift-R) to
view the Xcode console window.This window is where your printf, NSLog, and
CFShow messages are sent by default. In the unlikely case where NSLog messages
do not appear, use the Xcode organizer (Window, Organizer, Console) or open
/Applications/Utilities/Console to view NSLog messages instead.
n Running Instruments. Use Run, Start with Performance Tool to select an
Instruments template (such as Object Allocations or CPU Sampler) to use with the
Simulator. Instruments monitors memory and CPU use as your application runs.

Friday, September 18, 2009

call permission manager

The code I am using is as follows:

ApplicationPermissionsManager apm = ApplicationPermissionsManager.getInstance();
if (apm.getPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION) != ApplicationPermissions.VALUE_ALLOW) {
ApplicationPermissions ap = new ApplicationPermissions();
ap.addPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION);
ApplicationPermissionsManager.getInstance().invokePermissionsRequest(ap);
}

This brings up the interface for the user to set the permissions. In the Input Simulation options, the only option available is Deny, there is no Allow or Prompt. But on other options, for example Files, all the options are available. Also on the other devices the Input Simulation has all these options available.

Control the screen orientation

Details

BlackBerry smartphones with accelerometer support, such as the touch screen BlackBerry® Storm™ Series, are capable of changing the display orientation between portrait and landscape mode, depending on how the BlackBerry smartphone is held.

It may be desirable for certain applications to limit the possible orientations. For example, a video player application may need to fix the display orientation to landscape mode.

The screen can be oriented in any of four possible directions: north, south, east and west.

To set the allowable screen orientations, MIDlets should use code similar to the following example, prior to calling Display.setCurrent() from the MIDlet constructor.

DirectionControl dc =
DirectionControl)((Controllable)Display.getDisplay(this)).getControl("net.rim.device.api.lcdui.control.DirectionControl");

int directions = DirectionControl.DIRECTION_EAST | DirectionControl.WEST;

dc.setAcceptableScreenDirections(directions);

The above example forces the display into landscape mode.

Connected Limited Device Configuration (CLDC) applications should make the following call before any invocation of UiApplication.pushScreen().

int directions = net.rim.device.api.system.Display.DIRECTION_NORTH |
net.rim.device.api.system.Display.DIRECTION_SOUTH;

net.rim.device.api.ui.Ui.getUiEngineInstance().setAcceptableDirections(directions);

In the above example the display is forced into portrait mode once the BlackBerry smartphone user rotates the BlackBerry smartphone.


from

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800608/How_To_-_Control_the_screen_orientation.html?nodeid=1487645&vernum=0

Friday, September 11, 2009

How to use third part lib in BB project

Some related post here
http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=22240&query.id=82860#M22240

Basically, preverify the jar, make sure no other missing dependence packages. Import it into your project, or make a separated project to work as lib project.

Blackberry connections

Do not understand why BB makes a Http connection so complex, but still need to face it.

If you were trying these methods, then the preferred order, based on various posts on this forum, seems to be:
1) BIS-B
2) WAP 2
3) Direct TCP
4) WAP 1

This is the best post talking about this topic

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=29105#M29105

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=29103

What Is - Network Diagnostic Tool

From RIM

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is_-_Network_Diagnostic_Tool.html?nodeid=1450596&vernum=0



Details

BlackBerry smartphones support many different transports that facilitate reliable data communication between third-party applications and the Internet. The transports available are direct Transmission Control Protocol (TCP), BlackBerry® Mobile Data System (BlackBerry MDS), BlackBerry® Internet Service Browsing (BIS-B), BlackBerry® Unite!™ software, Wireless Access Protocol (WAP)1.0, WAP2.0 and Wi-Fi® technology. It is important to understand the differences between these transports and how and when to leverage each transport. It is also crucial to determine if a transport is available for use before trying to use it. The Network Diagnostic Tool is essentially a role model that answers all these questions and is a functional diagnostic tool for testing a URL over various transports supported by the BlackBerry solutions, as well as for displaying the values of many network attributes during the test period.

This article refers to the source code of the Network Diagnostic Tool, which can be downloaded here.

To better understand how each transport works, see the video Network Transports found on blackberrydeveloper.com.

Determining transport availability

The first step to determining the availability of a transport is to check if the ServiceRecord for that transport is available. This can be done programmatically as follows:

  1. Get the ServiceBook instance by calling the static method ServiceBook.getSB().
  2. Get the ServiceRecords from the ServiceBook by calling the instance method ServiceBook.getRecords().
  3. Iterate through each ServiceRecord and determine if it is for the transport you are looking for.

This is demonstrated in the Network Diagnostic Tool's IOThread.initializeTransportAvailability().

The next step is to determine if the BlackBerry smartphone has network coverage to communicate through the transport. This can be accomplished by calling the application programming interface (API) CoverageInfo.isCoverageSufficient(int coverageType).

Refer to the method IOThread.initializeTransportAvailability()for a sample implementation of this.

">Creating connections

Developer knowledge base article DB-00396 illustrates how to create an Hypertext Transfer Protocol (HTTP) or socket connection.

The IOThread.get*URL() methods in the source code shows how to construct URLs for each transport.

Once you have the URL you need, you can create an HTTPConnection instance using the Connector.open(String url) static method and start communicating with that URL. See the IOThread.do*() methods in the Network Diagnostic Tool source code to see a detailed implementation of this.

Note: The BIS-B transport is available only to partners of the BlackBerry Alliance Program, and therefore is not implemented in the attached source code of the Network Diagnostic Tool. For more information on the BlackBerry Alliance Program, visit http://na.blackberry.com/eng/partners/why_join.jsp.

Displaying network and radio information

Besides testing the different transports for a given URL, the Network Diagnostic Tool also displays network and radio information such as signal level, network name and type, and available network services. Refer to the method ReportScreen.displayNetworkInfo() in the Network Diagnostic Tool source code for more information on how to display this information.

RadioStatusListener

It is also possible for an application to listen for changes in the radio such as signal level and available network services. To accomplish this, you must implement the interface RadioStatusListener. The Network Diagnostic Tool implements this interface in the class named IOThread.

Automatically detecting wireless service providers

It is very useful to be able to detect wireless service providers, especially for applications using the Direct TCP transport for BlackBerry smartphones that operate using Global System for Mobile communications® (GSM®). For these BlackBerry smartphones, correct access point name (APN) information must be specified by the BlackBerry smartphone user before any application can leverage the Direct TCP transport.

APN information can also be set programmatically, which is demonstrated in the referenced Network Diagnostic Tool source code. The details are also explained in DB-00532. If the current wireless service provider for the BlackBerry smartphone can be determined, then the APN information can be set up programmatically from the application. This improves the BlackBerry smartphone user's experience because the APN does not need to be specified manually. To detect the wireless service provider, use a table that contains the name, mobile country code (MCC), mobile network code (MNC) and the APN details of each wireless service provider. Compare the MCC and MNC values returned by the BlackBerry smartphone against the values in the table. Once a match is found, set the corresponding APN information programmatically. For more information on how to read the MCC and MNC values from the BlackBerry smartphone, see DB-00688.

The complete process to automatically detect wireless service providers is also demonstrated by the Network Diagnostic Tool. The Network Diagnostic Tool stores the wireless service provider table in an Extensible Markup Language (XML) file that can be downloaded from here. This file must be stored on the BlackBerry smartphone in the following location: file:///store/netdiag/carrier_info.xml unless this path is changed in the source code. You can add details for as many wireless service providers as you want to the XML file.

Changes required for earlier versions of the BlackBerry Java Development Environment

Although this article is targeted for BlackBerry® Java® Development Environment (BlackBerry JDE) 4.5 or later, the source code of the Network Diagnostic Tool can be easily modified and compiled using earlier versions of the BlackBerry JDE. Consider the following changes:

  1. Before BlackBerry JDE 4.3, RadioStatusListener had an additional method named mobilityManagementEvent(int eventCode, int cause). This method must be implemented if you are using BlackBerry JDE 4.2 or earlier.
  2. CoverageInfo.COVERAGE_DIRECT is not supported until BlackBerry JDE 4.5. For BlackBerry JDE 4.3 or earlier, use CoverageInfo.COVERAGE_CARRIER.
  3. WLANInfo class is not available until BlackBerry JDE 4.5. For BlackBerry JDE 4.3 or earlier, use the following logic:
  4. if(CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_CARRIER,RadioInfo.WAF_WLAN, false)){
    coverageWiFi = true;
    wifiLog.addlog("Coverage Status: Online");
    }

  5. RadioInfo.NETWORK_SERVICE_GAN is not supported in BlackBerry JDE 4.2.1 or earlier. Remove any references to this constant for those versions of the BlackBerry JDE.
  6. RadioInfo.NETWORK_SERVICE_EVDO_ONLY and RadioInfo.NETWORK_SERVICE_UMTS are not supported in BlackBerry JDE 4.2.1 or earlier. Remove any references to these constants for those versions of the BlackBerry JDE.
  7. The CoverageInfo class is introduced in BlackBerry JDE 4.2.0. Remove any references to this class if you are using an earlier version of the BlackBerry JDE to compile this application. However, it is possible to do the following in versions of the BlackBerry JDE earlier than 4.2.0:
    1. if(RadioInfo.getSignalLevel() != RadioInfo.LEVEL_NO_COVERAGE) the BlackBerry smartphone has radio signal.
    2. if(RadioInfo.getNetworkService() & RadioInfo.NETWORK_SERVICE_DATA)>0 the BlackBerry smartphone has data connectivity.

Tuesday, September 8, 2009

How to get Blackberry device information?

String userAgent = "Blackberry" + DeviceInfo.getDeviceName() + "/" + getOsVersion() + " Profile/" + System.getProperty( "microedition.profiles" ) + " Configuration/" + System.getProperty( "microedition.configuration" ) + " VendorID/" + Branding.getVendorId();



public static String getOsVersion()
{ String version = "";
ApplicationDescriptor[] ad = ApplicationManager.getApplicationManager().getVisibleApplications();
for( int i = 0; i < ad.length; i++)
{ if( ad[i].getModuleName().trim().equalsIgnoreCase( "net_rim_bb_ribbon_app" ) )
{ version = ad[i].getVersion();
break;
}
}
return version;
}

Tuesday, September 1, 2009

How To - Compile a jar file into a BlackBerry Library

come from here

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800901/How_To_-_Compile_a_JAR_file_into_a_BlackBerry_Library.html?nodeid=801017&vernum=0


Details

You can include classes from other compiled JAR files in your application. To include these files, save the JAR file in a new project in the same workspace as your application. Make this new project a library application and make your application dependent on this library. You can then import all of its classes. The following steps make up this procedure.

To create a new project

  1. Open the workspace that contains your application's project.
  2. Create a new project.

To add a compiled JAR file to the project

  1. In the navigation pane, select the project.
  2. On the Build menu, select Project > Add File to Project.
  3. Select the appropriate JAR file and click Open.

To make the project a library

  1. In the navigation pane, select the project.
  2. Right-click and select Properties. The <Project name> Class Properties window appears.
  3. Click the Application tab.
  4. From the Project Type drop-down list, select Library.

To compile the project

  1. In the navigation pane, select the project.
  2. Right-click and click Build Project.

To make the project dependent on the new library

  1. In the navigation pane, select the project.
  2. Right-click and click Project Dependencies. The Class depends on <Project name:> window appears.
  3. Select the check box.

Your application can now import the classes in this JAR file with the import “xxx.yyy.*” command.