Saturday, February 21, 2009

Code : To Invoke applications


One of the new APIs found in BlackBerry JDE 4.0 is the net.rim.blackberry.api.invoke, which allows developers to gain controlled access to the Phone, Messages, Calendar, MemoPad, Tasks, and Address Book.

To specify the applications to invoke, use the default arguments provided in this API. The Application Argument API provides instances to access the applications mentioned above.

The following sample illustrates simple functions to make a phone call, given a number in a custom application, and to invoke the messaging application.

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.blackberry.api.invoke.*;
class appinvo extends UiApplication {
public static void main(String arg[]){
//create a new instance of the application
//and start the application on the event thread
appinvo application = new appinvo();
application.enterEventDispatcher();
}
public appinvo () {
pushScreen(new InnovactionScreen());//creating a screen
}
}
class InnovactionScreen extends MainScreen {
//variables for the user interface
LabelField _title;
EditField _phonefield;
String _value;
public InnovactionScreen() {
super();//invoke MainScreen constructor
//define title of the app
_title = new LabelField("Sample App", LabelField.ELLIPSIS
| LabelField.USE_ALL_WIDTH);
setTitle(_title);
//add user interface field
_phonefield = new EditField("Please Enter a #","");
this.add(_phonefield);//add the field to the MainScreen
//create e-mail menuItem
MenuItem menu1 = new MenuItem("e-mail",1,1) {
public void run () {
//using invoke api to "jump" from this app
//to email app
Invoke.invokeApplication
( Invoke.APP_TYPE_ADDRESSBOOK,
new AddressBookArguments
(AddressBookArguments.ARG_COMPOSE));
}
};
//add email menu to the MainScreen
this.addMenuItem(menu1);
//create phone menuItem
MenuItem menu2 = new MenuItem("Phone Them",2,2) {
public void run () {
//getting the value user input in the
//phonefield defined above
_value = _phonefield.getText();
//using invoke api to "jump" from this app
//to phone app
//it calls the number the user types
//in the phonefield
Invoke.invokeApplication(Invoke.APP_TYPE_PHONE,
new PhoneArguments
(PhoneArguments.ARG_CALL, _value));
}
};
this.addMenuItem(menu2);//add phone menu to menuItem
}
}

No comments:

Post a Comment

Place your comments here...