2012-05-22 16 views
0

FileSystemJournalListener不返回新捕获的图像路径。 我的相机将图像保存到SD卡/黑莓/图片/ ...Blackberry:FileSystemJournalListener不返回新捕获的图像路径

但听众给我的空白图像路径在 店/家庭/用户/图片/ Image_1337710522032.jpg

和实际保存的文件是在 sdcard /黑莓/图片/ IMG00010-20111019-1225.jpg

我该如何设置FileSystemJournalListener扫描SD卡的新添加的图像路径?

在此先感谢。

+0

请发布您的听众的代码。 –

回答

1

This is the appropriate example to follow来自BlackBerry开发人员文档。

在应用程序我有这样做,我的FileSystemJournalListener看起来像下面的代码。您必须遍历USN才能找到新图像。

有关FileSystemJournal以及如何检查新文件的更多信息,您也可以登录see this page

public class FileSystemListener implements FileSystemJournalListener, Runnable { 
     /** The last USN to have to search until, when looking for new files added to the file system */ 
     private long _lastUSN; 
     /** The filename of the new image */ 
     private String _imageFilename; 

     public void run() { 
      // TODO: do something with the new image 
     } 

     public FileSystemListener() { 
      // we record the next system USN before the Camera app has a chance to add a new file 
      _lastUSN = FileSystemJournal.getNextUSN(); 
     } 

     public void fileJournalChanged() { 
      long nextUSN = FileSystemJournal.getNextUSN(); 
      boolean imgFound = false; 
      // we have to search for the file system event that is the new image 
      for (long lookUSN = nextUSN - 1; (lookUSN >= _lastUSN) && !imgFound; --lookUSN) { 
      FileSystemJournalEntry entry = FileSystemJournal.getEntry(lookUSN); 
      if (entry == null) { 
       break; 
      } else { 
       String path = entry.getPath(); 
       if (path != null) { 
        if (path.endsWith("png") || path.endsWith("jpg") || path.endsWith("bmp") || path.endsWith("gif")) { 
         switch (entry.getEvent()) { 
         case FileSystemJournalEntry.FILE_ADDED: 
          // either a picture was taken or a picture was added to the BlackBerry device 
          _lastUSN = lookUSN; 
          _imageFilename = path; 
          imgFound = true; 

          // unregister for file system events? 
          UiApplication.getUiApplication().removeFileSystemJournalListener(this); 

          // let this callback complete before responding to the new image event 
          UiApplication.getUiApplication().invokeLater(this); 
          break; 
         case FileSystemJournalEntry.FILE_DELETED: 
          // a picture was removed from the BlackBerry device; 
          break; 
         } 
        } 
       } 
      } 
      } 
     } 
    } 
+0

谢谢。 以上代码可以检测添加到SD卡上的图像吗?或者它只跟踪内部存储器文件系统的变化? – user1407894

+0

@ user1407894,上面的代码可以检测添加到SDCard的图像。我刚刚运行了我使用此代码进行测试的应用程序。它适用于内部存储或SDCard。显然,这两个位置的路径将会不同('String path =')。但是,是的,它确实检测到媒体卡上的文件。 – Nate

+0

谢谢老兄。 :) 将现在检查它。 – user1407894