【问题标题】:How to scan all images available in a blackberry device如何扫描黑莓设备中可用的所有图像
【发布时间】:2011-11-01 15:37:16
【问题描述】:

我正在尝试在列表中显示blackberry 设备中可用的所有图像。如何使用 java api 扫描和获取黑莓中的所有图像名称?

【问题讨论】:

  • 这是一个非常广泛的问题。你自己尝试过什么?

标签: image listview blackberry java-me


【解决方案1】:

使用以下类来定位设备中的所有图像。一开始,你调用函数时没有给字符串任何值: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) { }
}

【讨论】:

  • 如果这是 jpg 文件,则代码未关闭 FileConnection 实例。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-16
  • 1970-01-01
  • 2011-02-11
相关资源
最近更新 更多