黑莓文件(Webworks)

时间:2012-05-29 15:06:03

标签: blackberry blackberry-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 - 我认为这是基于权限的,但我不相信我无法在相机上读取读取失败 - 任何人都知道什么?

干杯!

1 个答案:

答案 0 :(得分: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");

返回文件名数组。

希望这有助于某人!