- return

Blackberry Web Shortcut Programming

[NOTE: I can provide a shortcut application to anyone who needs one, the only charge is a donation to Oxfam
I cannot develop for much older devices as they require my computer to use an older java version which doesn't sit happily with the latest release, as mentioned below, the number of devices using older firmware is most likely negligible.]

Information about getting a shortcut on your BlackBerry homescreen that launches the web browser to a predefined site.
You have three options: push shortcut (requires BES based BlackBerry), simple post 4.1 code, more involved pre 4.1 code that works across more models



1 - Push shortcut - this method requires the end-user to be on you company BES and requires server based programming and well documented here



2 - From 4.1 onwards RIM have provided improved methods for spawing the web browser, the advantages are the small amount of code but you do lose backwards compatability with pre 4.1 devices:

import net.rim.blackberry.api.browser.Browser;
import net.rim.blackberry.api.browser.BrowserSession;
import net.rim.device.api.ui.UiApplication;

public class simpleshortcut extends UiApplication {
public static void main(String[] args){
simpleshortcut instance = new simpleshortcut();
instance.enterEventDispatcher();
}

public simpleshortcut() {
BrowserSession site = Browser.getDefaultSession();
site.displayPage("http://mywebsite.net");
System.exit(0);
}
}



3 - The final method which was the norm before the 4.1 api came out was much more verbose but is still useful if you want better legacy support (how many users you might have with pre 4.1 devices is questionable):

import net.rim.device.api.system.ApplicationDescriptor;
import net.rim.device.api.system.ApplicationManager;
import net.rim.device.api.system.ApplicationManagerException;
import net.rim.device.api.system.CodeModuleManager;
import net.rim.device.api.ui.UiApplication;

public class legacyshortcut extends UiApplication {
public static void main(String[] args){
legacyshortcut instance = new legacyshortcut();
instance.enterEventDispatcher();
}

public legacyshortcut() {
boolean retval = true;
int handle = CodeModuleManager.getModuleHandle("net_rim_bb_browser_daemon");
if (handle <=0 ){
System.exit(0);
}else{
ApplicationDescriptor[] browserDescriptors = CodeModuleManager.getApplicationDescriptors(handle);
if (browserDescriptors == null ){
System.exit(0);
}else{
if ( browserDescriptors.length <=0 ){
System.exit(0);
}else{
String[] args = {"url", "http://mywebsite.net"};
ApplicationDescriptor descriptor = new ApplicationDescriptor(browserDescriptors[0],"url invocation", args,null, -1, null, -1,ApplicationDescriptor.FLAG_SYSTEM);
try{
ApplicationManager.getApplicationManager().runApplication(descriptor);
}catch(ApplicationManagerException e){
System.exit(0);
}
System.exit(0);
}
}
}
}
}


>> return to articles menu