科尔多瓦相机 PictureSourceType PHOTOLIBRARY v SAVEDPHOTOALBUM

4

这些值都不能启动Android PhoneGap应用程序中的照片库!!!

当使用任何这些值调用getPicture方法时,它都无法打开照片库。

我是使用PhoneGap构建云服务来创建应用程序的。

请帮忙解决问题,

示例代码 -

function getPhoto(source) {
  alert("getting photo");
  // Retrieve image file location from specified source
  navigator.camera.getPicture(onPhotoURISuccess, onFail, { destinationType: destinationType.FILE_URI, sourceType: source });
}

你能否在调用getPhoto时,使用console.log输出source和destinationType的值,以便查看它们的实际内容?此外,我假设onPhotoURISuccess和OnFail是在代码中其他地方定义的函数,对吗? - Daniel Bank
是的,onPhotoURISuccess和OnFail在代码的其他地方定义了。 - Lanre Sideeq
在安卓手机上构建时,如何在控制台记录源和目标类型? - Lanre Sideeq
实际上,您可以访问在设备上运行的 PhoneGap 的 JavaScript 控制台。请参见此网站:http://debug.phonegap.com/。基本上,您需要向 DOM 添加一个脚本元素,然后通过访问网页来访问控制台。非常方便。 - Daniel Bank
顺便说一句,我猜你需要将destinationType.FILE_URI更改为navigator.camera.DestinationType.FILE_URI。 - Daniel Bank
2个回答

8

Camera.PictureSourceType.PHOTOLIBRARY == 整个图库

Camera.PictureSourceType.SAVEDPHOTOALBUM == 相机相册

如果您希望用户上传手机上的任何图片,请使用PHOTOLIBRARY。 或者,如果您只想让用户上传手机相机拍摄的照片,则使用SAVEDPHOTOALBUM


这在哪里有文档记录?我正在使用SAVEDPHOTOALBUM,但我无法上传任何东西到我的Nexus 6。 - Paranoid Android
这个链接 https://github.com/apache/cordova-plugin-camera 中提到了两种选项,但并没有清楚地解释使用情况。我在2014年使用过它,但是库可能已经发生了变化。 - Sushan Ghimire
我发现在Android上这两个选项是相同的。 - Paranoid Android

0

也许下面的代码行可以帮助你。

function getImage()
{
    // Retrieve image file location from specified source
    navigator.camera.getPicture(onCapturePhotoSuccess, onCapturePhotoError,{ quality: 80, 
        destinationType: navigator.camera.DestinationType.DATA_URL,
        sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
    });
}

function onCapturePhotoSuccess(imageURI) 
{   
    var smallImage = document.getElementById('id_for_setting_pic_somewhere_in_html');
        smallImage.src = "data:image/jpeg;base64," + imageURI;
}


function onCapturePhotoError(message) 
{
    console.log('Captured Failed because: ' + message); 
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接