Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Open a file in a Documents To Go application

by Retired ‎02-16-2010 10:00 AM - edited ‎02-18-2010 09:28 AM (6,375 Views)

Summary


This article applies to the following:

    BlackBerry® Device Software 4.5.0 and later Documents To Go®


Details


The Documents To Go suite of applications supports programmatic invocation through the use of the Java® Specification Request (JSR) 211 Content Handler application programing interface (API). The sample below illustrates how to open a Microsoft® Word document in the Word To Go application. The sample can also be downloaded here.



package com.samples.docs2gosample;
import javax.microedition.content.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.content.BlackBerryContentHandler;

public class Docs2GoSample extends UiApplication
{
EditField _ef;

// Entry point for application
public static void main(String[] args)
{
Docs2GoSample theApp = new Docs2GoSample();
theApp.enterEventDispatcher();
}

public Docs2GoSample()
{
MainScreen mainScreen = new MainScreen();
mainScreen.setTitle("Use the menu to open a document");
MenuItem menu = new MenuItem("Open File", 40, 40)
{
public void run()
{
try
{
//Create the invocation request.
Invocation invocation = new Invocation(_ef.getText());
invocation.setAction(ContentHandler.ACTION _OPEN);
invocation.setResponseRequired(false);

//Use the registry to perform the //invocation.
Registry registry = Registry.getRegistry("com.samples. docs2gosample.Docs2GoSample");
registry.invoke(invocation);
}
catch (Exception ex)
{
System.out.println("Exception: " + ex.toString());
}
}
};
mainScreen.addMenuItem(menu);

//An EditField where a user can enter the path to the
//document to be opened. An example path is pre- //populated.
_ef = new EditField("File to Open: ", "file:///SDCard/ aDoc.doc");
mainScreen.add(_ef);

pushScreen(mainScreen);
}
}




Contributors
Users Online
Currently online: 4 members 2,048 guests
Please welcome our newest community members: