This is a migrated thread and some comments may be shown as answers.

navigator.camera.getPicture not working in android

1 Answer 246 Views
Android Devices
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tim
Top achievements
Rank 1
Tim asked on 16 Jul 2013, 03:36 PM
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.

1 Answer, 1 is accepted

Sort by
0
Accepted
Tim
Top achievements
Rank 1
answered on 16 Jul 2013, 04:19 PM
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.
Tags
Android Devices
Asked by
Tim
Top achievements
Rank 1
Answers by
Tim
Top achievements
Rank 1
Share this question
or