Java Blackberry:FileSystemJournalListener未返回新捕获的映像路径
FileSystemJournalListener不返回新捕获的映像路径。 我的相机将图像保存到SD卡/blackberry/pictures/… 但听众给了我一个空白的图像路径 商店/主页/用户/图片/图像_1337710522032.jpg 实际保存的文件位于 sdcard/BlackBerry/pictures/IMG00010-20111019-1225.jpg 我应该如何设置FileSystemJournalListener来扫描SD卡以查找新添加的映像路径 提前感谢。来自BlackBerry开发者文档 在我的应用程序中,我的Java Blackberry:FileSystemJournalListener未返回新捕获的映像路径,java,blackberry,Java,Blackberry,FileSystemJournalListener不返回新捕获的映像路径。 我的相机将图像保存到SD卡/blackberry/pictures/… 但听众给了我一个空白的图像路径 商店/主页/用户/图片/图像_1337710522032.jpg 实际保存的文件位于 sdcard/BlackBerry/pictures/IMG00010-20111019-1225.jpg 我应该如何设置FileSystemJournalListener来扫描SD卡以查找新添加的映像路径 提前感谢。来自BlackB
FileSystemJournalListener
看起来像下面的代码。您必须遍历USN才能找到新映像
您还可以查看有关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;
}
}
}
}
}
}
}
请为您的听众发布代码。谢谢。上述代码能否检测SD卡上添加的图像?或者它只跟踪内部内存文件系统的更改?@user1407894,是的,上面的代码可以检测添加到SD卡的图像。我刚刚运行了我构建的应用程序,该应用程序使用此代码进行测试。它适用于内部存储或SD卡。显然,这两个位置的路径不同(
stringpath=
)。但是,是的,它确实能检测到媒体卡上的文件。谢谢你,伙计。:)现在将检查它。@user1407894。没问题。我还要指出,我上面的代码只找到一个图像。找到新映像后,它将停止侦听更多文件系统事件。这对我的应用程序是正确的,但对你的应用程序可能不正确。无论如何,如果你想让你的应用程序继续等待更多图像,你可以删除我对removeFileSystemJournalListener
的呼叫。谢谢你宝贵的评论:)