0

我正在尝试(非常简单)使用 webworks 获取相机目录的文件列表。我正在尝试的代码如下:

function displayPhotos(id) {
try {
    var Dir, path, items;

    if ((window.blackberry === undefined) || (blackberry.io === undefined) || (blackberry.io.file === undefined)) {
        appendContent("photoDetails", "<p><i><b>blackberry.io.file</b> object not found (likely cause is WebWorks APIs are not supported by this user agent).</i></p>");
        debug.log("displayPhotos", "blackberry.io.file object is undefined.", debug.error);
        return false;
    }

    Dir = blackberry.io.dir;

    path = "";      
    path = "file:///Device/home/user/camera"";


    items = Dir.listFiles(path);

    console.log(items);

    //setContent(id, formatAsHTML(path, items));

}
catch(e) {
    console.log("displayPhotos", e, debug.exception);
}
}

我得到的只是错误1004-我认为这是基于权限的,但我不相信我无法在相机上读取失败-有人知道吗?

干杯!

4

1 回答 1

2

好吧,我想通了,希望这有助于任何人获得可怕的黑莓网络工作错误 1004。

您需要更改存储路径中的设备。就是这样。这个例子有效:

function displayPhotos(myFolder) {
    try {
        var Dir, path, items;       
        Dir = blackberry.io.dir;

    path = "";      
    if (myFolder != undefined){
        path = myFolder;
    } else {
        path = "file:///store/home/user/pictures";
        //file:///store/home/user/camera
    }

    items = Dir.listFiles(path);        
    return items;
}
catch(e) {
    console.log("displayPhotos", e, debug.exception);
}
}


function displayFiles(myFolder) {
try {
    console.log("displayFiles", "in " + myFolder);
    return displayPhotos(myFolder);
}
catch(e) {
    console.log("displayFiles", e, debug.exception);
}
}

你可以这样称呼它:

 displayFiles();

或者像这样指定一个文件夹:

 displayFiles("file:///store/home/user/camera");

返回文件名数组。

希望这对某人有帮助!

于 2012-05-30T10:55:23.553 回答