Wednesday, March 3, 2010

Open a doc file saved in SD Card programmatically - Blackberry 8900

A doc file saved in SD Card can be opened by WordToGo Application in Blackberry 8900. But to open it Programmatically, you need to use the following Lines of Code.

BrowserSession brSession = Browser.getDefaultSession();
brSession.displayPage("file:///SDCard/documents/hello.doc");




Here the doc file will be opened from WordToGo, but actually we are making a the call to the Blackberry Browser. It will redirect to appropriate application via understanding the extension of the file.
But if we directly try to open the doc file by launching the WordToGo Application using Application Manager, the block of code is given below,


ApplicationManager manager = ApplicationManager.getApplicationManager();
int modHandle = CodeModuleManager.getModuleHandle("WordToGo");

ApplicationDescriptor[] apDes = CodeModuleManager.getApplicationDescriptors(modHan dle); ApplicationDescriptor descriptor = apDes[0];
String[] args = {"file:///SDCard/documents/hello.doc"};

ApplicationDescriptor newDescriptor = new ApplicationDescriptor(descriptor, descriptor.getName(), args);
try {
manager.runApplication(newDescriptor);
} catch (ApplicationManagerException ex) {
System.out.println("Exception: " + ex.toString());
}
catch(Exception ex){
System.out.println("Exception: " + ex.toString());
 }



The result will launch the WordToGo Application. But the doc file will not be opened throwing a DocsToGoException.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...