How to fetch all gallery image of mobile using cordova?
Asked Answered
U

3

9

I want to fetch the complete gallery of a mobile device to show them in a custom grid, is it possible? Right now I am using $cordovaImagePicker which is redirecting me to the gallery and then after selecting the image I am getting the Uri of that image. Instead of that I want the complete gallery images uri auto selected.

Controller

$scope.getImageFromGallery = function() {
    // Image picker will load images according to these settings
    var options = {
        maximumImagesCount: 1, // Max number of selected images, I'm using only one for this example
        width: 800,
        height: 800,
        quality: 80 // Higher is better
    };

    $cordovaImagePicker.getPictures(options).then(function(results) {
        // Loop through acquired images
        for (var i = 0; i < results.length; i++) {
            alert(results);
            $scope.image = results[i];
            // Print image URI
        }
    }, function(error) {
        console.log('Error: ' + JSON.stringify(error)); // In case of error
    });
}
Underquote answered 12/1, 2016 at 11:21 Comment(3)
yes ,for IOS and android and windows too :)Underquote
Similar unanswered question: #28997884Crystlecs
@Underquote did you get ?Reger
S
4

the easiest way to do this is to use cordova-gallery-api plugin, refer to the following example :

 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);});
};
Station answered 18/1, 2016 at 13:45 Comment(0)
R
1

Add this plugin,

cordova plugin add https://github.com/wymsee/cordova-imagePicker.git

Controller

$scope.images = [];
$scope.selectImages = function() {
    $cordovaImagePicker.getPictures(
        function(results) {
            for (var i = 0; i < results.length; i++) {
                $scope.images.push(results[i]);
            }
            if (!$scope.$$phase) {
                $scope.$apply();
            }
        },
        function(error) {
            console.log('Error: ' + error);
        }
    );
};

Html

<div class="row responsive-md">
    <div class="col col-25" ng-repeat="image in images">
        <img ng-src="{{image.src}}" width="100%" />
    </div>
</div>

Tutorial

Reger answered 21/1, 2016 at 9:41 Comment(0)
V
0

check this link, may be it is useful for you.

http://www.digitalnoiz.com/mobile-development/photo-gallery-with-phonegap-and-jquery-mobile/

Virgy answered 17/1, 2016 at 17:35 Comment(1)
i will check and get back to you Thanks for your reply buddy :)Underquote

© 2022 - 2024 — McMap. All rights reserved.