navigator.camera.getPicture not working in android

2 posts, 1 answers
  1. Tim
    Tim avatar
    2 posts
    Member since:
    Sep 2010

    Posted 16 Jul 2013 Link to this post

    So I have a function something like this:

    _getVideoFromLibrary: function() {
            var that= this;
            
            navigator.camera.getPicture(
                function(){ that._onPhotoURISuccess.apply(that,arguments); }, 
                function(){ that._onLibraryFail.apply(that,arguments); } 
            ,{
                quality: 50,
                destinationType: that._destinationType.FILE_URI,
                sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
                mediaType: Camera.MediaType.VIDEO
            });        
        },

    _onPhotoURISuccess: function(imageURI) {
            var that = this;
            console.log(imageURI);
           etc etc etc ...
    },

    It grabs a video from the library of saved videos and outputs the path in the console. On iOS it works great, I get correct path, I can then upload it, whatever. On android I get something like "content://media/external/video/media/213". 

    What am I supposed to do with this information? It's not a path to anything usable that I can see.
  2. Answer
    Tim
    Tim avatar
    2 posts
    Member since:
    Sep 2010

    Posted 16 Jul 2013 Link to this post

    Well this isn't exactly what I'd call an elegant solution, but it's quick and dirty.

    _onPhotoURISuccess: function(imageURI) {
            var that = this;
            if (imageURI.indexOf('content://') > -1) {
                try {
                    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) { console.log(fileSystem.name); }, function(evt) { });
                    window.resolveLocalFileSystemURI(imageURI, function(fileEntry) {
                
                        console.log(fileEntry.fullPath);
                        
                    }, function(evt){ });
                } catch(err) {
                    console.log('Error: ' + err);
                }
                
            }


    you basically just have to use the requestFileSystem object to translate the imageURI to the fileEntry.fullPath.
Back to Top