Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get picture location - Phonegap camera

I used this code:

function getPicture(){
  navigator.camera.getPicture(onSuccess, onFail, {
    quality: 50,
    destinationType: Camera.DestinationType.FILE_URI,
    sourceType : Camera.PictureSourceType.SAVEDPHOTOALBUM
  });
}
function onSuccess(imageURI) {
  img_uri = imageURI;
  alert(img_uri);
  Plugin.callNativeFunction(nativePluginResultHandler, nativePluginErrorHandler, 'success', img_uri);
}

I want to get a URI like this: "/mnt/sdcard/Pictures..." but the alert gave me a URI like "content://media/external/images/media/3915".

What can I do?

like image 681
Yehuda Avatar asked Nov 25 '12 11:11

Yehuda


1 Answers

You can use window.resolveLocalFileSystemURI to get the true path. Your onSuccess method would look like:

function onSuccess(imageURI) {
  img_uri = imageURI;
  alert(img_uri);
  window.resolveLocalFileSystemURI(img_uri, function(fileEntry) {
      alert(fileEntry.fullPath);
      Plugin.callNativeFunction(nativePluginResultHandler, nativePluginErrorHandler, 'success', fileEntry.fullPath);
  }, onError);      
}
like image 94
Simon MacDonald Avatar answered Oct 17 '22 11:10

Simon MacDonald