[ 
https://issues.apache.org/jira/browse/CB-5398?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16457860#comment-16457860
 ] 

Giuliano Pascali commented on CB-5398:
--------------------------------------

Hi guys after a day I found a solution it works for me. My target was to upload 
without edit photo from gallery with two fast clicks.
The solution I found was to copy the file that we can't access and put in the 
src of our img.
Then we use the copy.
Here is the full code. Hope you enjoy. One time I can give my part.



<script>
 $(document).ready(function(){


 // Take photo from camera
 $('#but_take').click(function(){
 
 navigator.camera.getPicture(onSuccess, onFail, { quality: 20,
 destinationType: Camera.DestinationType.FILE_URL 
 });
 });

// Take photo from gallery

$("#but_select").click(function(){
capturePhoto()
});


function onFail(message) {
 alert('Failed because: ' + message);
}

function capturePhoto() {
 navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
 sourceType: Camera.PictureSourceType.PHOTOLIBRARY, 
 destinationType: Camera.DestinationType.FILE_URI,
 savePhotoToAlbum : true
 });
}

function onPhotoURISuccess(imageURI) {
 createFileEntry(imageURI);
 
}

function createFileEntry(imageURI) {
 window.resolveLocalFileSystemURI(imageURI, copyPhoto, fail); 
}

function copyPhoto(fileEntry) {

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) { 
 fileSys.root.getDirectory("photos", \{create: true, exclusive: false}, 
function(dir) { 
 
 fileEntry.copyTo(dir, "file.jpg", onCopySuccess, fail); 
 }, fail); 
 }, fail); 
}

function onCopySuccess(entry) {
//alert(entry.toURL())


var image = document.getElementById('img');
image.src = entry.toURL() + '?' + Math.random();
 console.log(entry.fullPath)
}

function fail(error) {
 console.log(error.code);
}
 });
 </script>

<div style="margin:0 auto; width:30%!important;text-align: center;">
 <img src="img/cam2.jpg" id='img' style="width: 100px; height: 100px;">
 </div><br/>
 <div style="width:100%; text-align:center; padding:10px;">
 <button id='but_take'>Take photo</button>
 <button id='but_select'>Select photo from Gallery</button>
 </div>

> Pick image from Library or Photo album on android 4.4
> -----------------------------------------------------
>
>                 Key: CB-5398
>                 URL: https://issues.apache.org/jira/browse/CB-5398
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-android, cordova-plugin-camera
>    Affects Versions: 2.9.0, 3.2.0
>         Environment: android 4.4
>            Reporter: jcesarmobile
>            Assignee: Mike Billau
>            Priority: Major
>             Fix For: 3.5.0
>
>
> An android 4.4 try to pick a photo using pictureSource.PHOTOLIBRARY or 
> pictureSource.SAVEDPHOTOALBUM and return type destinationType.FILE_URI.
> Now android 4.4, when you select the above options, it opens an "open from" 
> dialog that  let you choose from new places as "Recent", "Drive", "Images" 
> and "Downloads" (the names might not be the same as I use the device in 
> spanish and translated it).
> If you choose any of them, you get an error, AndroidProtocolHandler, unable 
> to open content URL: the url here with a content://com.android.providers 
> format.
> I've tested on phonegap 2.9 because this is the version I use, but I suppose 
> it affects all of them. (in fact I use 2.9.1)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to