2011-10-31 114 views
1

我試圖在列表中顯示blackberry設備中可用的所有圖像。如何使用java apis掃描並獲取黑莓中的所有圖像名稱?如何掃描黑莓設備中的所有圖像

+1

這是一個非常寬泛的問題。你有什麼自己嘗試過的? –

回答

2

使用以下類來查找設備中的所有圖像。在開始時,您調用函數時不會給字符串賦予任何值: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) { } 
} 
+0

如果這是一個jpg文件,代碼會留下未關閉的'FileConnection'實例。 –

+0

你是對的,我糾正了這一點 –