2012-11-25 36 views
7

tôi đã sử dụng mã này:Nhận vị trí hình ảnh - camera PhoneGap

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

Tôi muốn có được một URI như thế này: "/ mnt/sdcard/Hình ..." nhưng cảnh báo đã cho tôi một URI như " nội dung: // media/external/images/media/3915 ".

Tôi có thể làm gì?

Trả lời

8

Bạn có thể sử dụng window.resolveLocalFileSystemURI để nhận đường dẫn thực. Phương thức onSuccess của bạn sẽ trông giống như:

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

Cảm ơn !! nó hoạt động ... :) – Yehuda

+0

btw. Tôi nhận được một lỗi mà 'resolveLocalFileSystemURI' không được chấp nhận và nên sử dụng từ bây giờ' resolveLocalFileSystemURL' (để bạn có thể cập nhật câu trả lời của bạn;)) – mrmnmly

Các vấn đề liên quan