java - 黑莓:FileSystemJournalListener 未返回新捕获的图像路径

标签 java blackberry

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

但是听众给我空白图像路径 商店/首页/用户/图片/Image_1337710522032.jpg

实际保存的文件位于 sdcard/BlackBerry/图片/IMG00010-20111019-1225.jpg

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

提前致谢。

最佳答案

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

在我执行此操作的应用程序中,我的 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;
                      }
                   }
                }
             }
          }
       }
    }

关于java - 黑莓:FileSystemJournalListener 未返回新捕获的图像路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10708549/

相关文章:

android - 在 Android、iOS 和 Blackberry 上嵌入字体——是否有万无一失的解决方案?

java - 我们能区分黑莓是处于USB模式还是充电模式吗?

c# - 当逻辑基本相同时可以复制和粘贴单元测试吗?

java - JDBC中批量插入

java - 从 mp4 中提取音轨并将其保存到可播放的音频文件

java - 如何在maven构建之前运行一个类?

java - MongoRepository findByCreatedAtBetween 没有返回准确的结果

java - Blackberry JDE 生成错误的 .jad 文件(与编译的 .cod 文件不匹配)

android - 是否有任何软件可以让我为多种类型的手机开发应用程序?

blackberry - 无需签名 key 即可将 Java 代码部署到 BlackBerry 设备