我在使用 Phonegap 1.4.1 时遇到错误。
我创建的phonegap应用程序在拍照后返回到应用程序后重新启动。
这是我正在使用的代码:
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI });
}
function onPhotoURISuccess(imageURI) {
// Uncomment to view the image file URI
// console.log(imageURI);
// Get image handle
//
var largeImage = document.getElementById('largeImage');
// Unhide image elements
//
largeImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
//
largeImage.src = imageURI;
}
我遇到同样的问题两天了,直到我发现您应该有权获取您在设备中拍摄的图像文件。默认情况下,没有返回图像的权限,因此它返回 null 并且您的应用程序崩溃。
如果您在 XCode 中使用 Cordova/PhoneGap,那么您还应该在 www 文件夹中创建 Config.xml 文件,并授予访问图像文件的权限。
<feature name="http://api.phonegap.com/1.0/device" />
<feature name="http://api.phonegap.com/1.0/battery"/>
<feature name="http://api.phonegap.com/1.0/camera"/>
<feature name="http://api.phonegap.com/1.0/contacts"/>
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/geolocation"/>
<feature name="http://api.phonegap.com/1.0/media"/>
<feature name="http://api.phonegap.com/1.0/network"/>
<feature name="http://api.phonegap.com/1.0/notification"/>
如果您使用的是 Android,请授予 AndroidManifest.xml 文件权限。
您可以在此处找到 config.xml 文件的所有内容:https://build.phonegap.com/docs/config-xml https://build.phonegap.com/docs/config-xml
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)