ionic + cordova 使用 cordova-gallery-api 獲取本地相冊全部圖片

cordova-gallery-api 插件定義一個全局galleryapi對象,提供查詢圖庫相冊的方法javascript

 

安裝 cordova-gallery-api:html

cordova plugin add https://github.com/subitolabs/cordova-gallery-api.git


調用方法:
java

document.addEventListener('deviceready', function()
{
    var $content = document.getElementById("content");

    $content.innerHTML = "Loading albums ...";

    galleryAPI.getAlbums(function(items)
    {
        var html = "";

        for(var i = 0; i < items.length; i++)
        {
            var album = items[i];

            html += '<a href="javascript:loadAlbum(\'' + album.title + '\')" class="album"><span>' + escape(album.title) + '</span></a>';
        }

        $content.innerHTML = html;

    }, function(error){alert(error);});

    window.loadAlbum = function(albumName)
    {
        galleryAPI.getMedia(albumName, function(items)
        {
            var html = "";

            for(var i = 0; i < items.length; i++)
            {
                var media = items[i];

                html += '<a href="javascript:void()" class="media"><img src="file://' + media.thumbnail + '" /></a>';
            }

            $content.innerHTML = html;

        }, function(error){alert(error);});
    };

}, false);
相關文章
相關標籤/搜索