Nativescript: How to get photo list from gallery

六月ゝ 毕业季﹏ 提交于 2019-12-24 18:12:53

问题


The thing is I need to get photos from gallery automatically. I've read that ImagePicked is used to pick up photo from image store but it provides just in manual way (user does it by self). Are there any opportunity get access to gallery, take list of photos and used them in an application? Of course if are is it possible to filter them by criteria (get photos by date range)?


回答1:


GingerComa, on Android you could try this:

import * from "file-system";

var tempPicturePath = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DCIM).getAbsolutePath();

var folder : Folder = Folder.fromPath(tempPicturePath);

folder.getEntities()
    .then(entities => {
        // entities is array with the document's files and folders.
        entities.forEach(entity => {
            // console.log(entity.name);
            // console.log(entity.path);
            // console.log(entity.lastModified);
            this.folderEntities.push(
                new FolderEntity(entity.name, entity.path, entity.lastModified.toString())
            );
        });
    }).catch(err => {
        // Failed to obtain folder's contents.
        console.log(err.stack);
    });


来源:https://stackoverflow.com/questions/48514494/nativescript-how-to-get-photo-list-from-gallery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!