2011-02-18 64 views
2

我想讓應用程序可以獲取所有圖像,無論是在手機還是在外部存儲器中。我想在我的應用程序中導入所有圖像。怎麼可能?我知道可以通過文件連接。但沒有得到確切的想法。文件連接+ j2me

回答

6
  1. 使用到每一根依次使用FileConnection fconn = (FileConnection)Connector.open(root)
  2. 使用fconn.list()文件夾列表FileSystemRegistry.listRoots()
  3. 打開連接獲取所有的文件系統的根。
  4. 對於列表中的每個條目,如果以圖像擴展名(file.getName().endsWith(".png")等)結尾,則它是圖像。
  5. 如果條目是一個文件夾(file.isDirectory()返回true),然後使用fconn.setFileConnection(folder)遍歷到該目錄/
  6. 做同樣的遞歸在所有根的所有文件夾。
+0

感謝您的答覆,但我不能夠在我MOTORLA A1200.I打開這個應用程序曾試圖安裝的應用程序,但應用程序親近,而不是讓這些文件 – shweta 2011-02-18 10:02:07

+0

什麼網址靈魂我寫的名單將圖像導入到我的應用程序中。圖像位於手機內存中的文件夾名稱 - 我的圖像 – shweta 2011-02-18 11:22:59

2

這是我曾經用於我的應用程序的代碼片段。它或多或少在時髦的步驟中也是如此。

protected void showFiles() { 
     if (path == null) { 
      Enumeration e = FileSystemRegistry.listRoots(); 
      path = DATAHEAD; //DATAHEAD = file:/// 
      setTitle(path); 
      while (e.hasMoreElements()) { 
       String root = (String) e.nextElement(); 
       append(root, null); 
      } 
      myForm.getDisplay().setCurrent(this); 
     } else { 
         //this if-else just sets the title of the Listing Form 
         if (selectedItem != null) { 
          setTitle(path + selectedItem); 
         } 
         else { 
          setTitle(path); 
         } 
      try { 
// works when users opens a directory, creates a connection to that directory 
       if (selectedItem != null) { 
        fileConncetion = (FileConnection) Connector.open(path + selectedItem, Connector.READ); 
       } else // works when presses 'Back' to go one level above/up 
       { 
        fileConncetion = (FileConnection) Connector.open(path, Connector.READ); 
       } 
// Check if the selected item is a directory 
       if (fileConncetion.isDirectory()) { 
        if (selectedItem != null) { 
         path = path + selectedItem; 
         selectedItem = null; 
        } 
        //gathers the directory elements 
        Enumeration files = fileConncetion.list(); 
        while (files.hasMoreElements()) { 
         String file = (String) files.nextElement(); 
         append(file, null); 
        } 
// 
        myForm.getDisplay().setCurrent(this); 
        try { 
         if (fileConncetion != null) { 
          fileConncetion.close(); 
          fileConncetion = null; 
         } 
        } catch (IOException ex) { 
         ex.printStackTrace(); 
        } 
       }//if (fileConncetion.isDirectory()) 
       else { 
        System.out.println(path); 
        //if it gets a file then calls the publishToServer() method 
        myForm.publishToServer(); 

       }