Zach
Zach

Reputation: 10129

How to scan all images available in a blackberry device

I am trying to display all the images available in a blackberry device inside a list. How can I scan and fetch all images names in blackberry using java apis?

Upvotes: 1

Views: 149

Answers (1)

Farid Farhat
Farid Farhat

Reputation: 2310

Use the following class to locate all the images in the device. At the beginning, you call the function without giving any value to the string: checkImages("");

public void checkImages(String imagePath) {
    String path = "";
    if (imagePath.equals(""))
        path = "file:///SDCard/";
    else
        path = imagePath;
    try {
        FileConnection fileConnection = (FileConnection)Connector.open(path);
        if (fileConnection.isDirectory()) {
            Enumeration directoryEnumerator = fileConnection.list("*", true);
            Vector contentVector = new Vector();
            while(directoryEnumerator.hasMoreElements()) {
                contentVector.addElement(directoryEnumerator.nextElement());
            }
            fileConnection.close();
            for (int i = 0 ; i < contentVector.size() ; i ++) {
                String name = (String) contentVector.elementAt(i);
                checkImages(path + name);
            }
        }
        else {
            if (path.toLowerCase().endsWith(".jpg")) {
                imm.addElement(path); // your Vector
                fileConnection.close();
            }
        }
    } catch (Exception ex) { }
}

Upvotes: 2

Related Questions