Back to all posts
BlackBerryMobile DevelopmentJava

Open a Doc File Saved in SD Card Programmatically – BlackBerry 8900

SathishMarch 4, 2010

Opening files from the SD card programmatically on BlackBerry requires using the appropriate APIs.

Code Example

java
import net.rim.device.api.system.Application;
import net.rim.device.api.content.ContentHandler;
import net.rim.device.api.content.ContentHandlerRegistry;
import javax.microedition.content.Invocation;
import javax.microedition.content.Registry;

public class FileOpener {
    
    public static void openFile(String filePath) {
        try {
            // Create invocation for the file
            Invocation invocation = new Invocation(filePath);
            
            // Get the registry
            Registry registry = Registry.getRegistry(
                Application.getApplication().getClass().getName()
            );
            
            // Invoke the appropriate handler
            registry.invoke(invocation);
            
        } catch (Exception e) {
            System.out.println("Error opening file: " + e.getMessage());
        }
    }
}

// Usage
String sdCardPath = "file:///SDCard/Documents/myfile.doc";
FileOpener.openFile(sdCardPath);

File Paths

  • SD Card: file:///SDCard/
  • Device Memory: file:///store/

Permissions

Add to your application descriptor:

xml
<rim:permission>read_device_files</rim:permission>
0claps
Share this post

Comments

Protected by reCAPTCHA v3

No comments yet. Be the first to comment.