Blackberry:FileSystemJournalListener不返回新捕获的图像路径

时间:2012-05-22 19:13:09

标签: java blackberry

FileSystemJournalListener不返回新捕获的图像路径。  我的相机将图像保存到sdcard / blackberry / pictures /...

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

并且实际保存的文件位于 SD卡/黑莓/图片/ IMG00010-20111019-1225.jpg

我如何设置FileSystemJournalListener来扫描sdcard以获取新添加的图像路径?

提前致谢。

1 个答案:

答案 0 :(得分:1)

来自BlackBerry开发人员文档的

This is the appropriate example to follow

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

您还可以see this page了解有关FileSystemJournal以及如何检查新文件的详细信息。

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;
                      }
                   }
                }
             }
          }
       }
    }