简体   繁体   中英

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?

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);      
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM