【发布时间】:2012-07-11 19:11:08
【问题描述】:
我在 Dreameweaver CS6 中使用最新版本的 phonegap 软件。我从 github 网站上获取了起始示例 HTML 文件并将其导入 DW。然后,我测试了该应用程序,并使用了我的位置、地图等。
但是,我现在更改了代码,以便能够在我的 Android 手机上拍照或选择图片,并且每次我这样做/或关闭应用程序时。
HTML代码是:
<!DOCTYPE html>
<html>
<head>
<title>Capture Photo</title>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8">
var pictureSource; // picture source
var destinationType; // sets the format of returned value
document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
function onPhotoDataSuccess(imageData) {
var smallImage = document.getElementById('smallImage');
smallImage.style.display = 'block';
smallImage.src = imageData;
}
function onPhotoURISuccess(imageURI) {
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.src = imageURI;
}
function capturePhoto() {
navigator.camera.getPicture(getPhoto, onFail, { quality: 50, destinationType: destinationType.FILE_URI });
}
function capturePhotoEdit() {
// Take picture using device camera, allow edit, and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 100, allowEdit: false });
}
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 100,
destinationType: destinationType.FILE_URI,
sourceType: source });
}
function onFail(message) {
alert('Failed because: ' + message);
}
</script>
</head>
<body>
<button onclick="capturePhoto();">Capture Photo</button> <br>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
<img style="display:none;" id="largeImage" src="" />
</body>
</html>
而 config.xml 是:
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.xxxxxxxx.DKGApp"
version = "1.0.0">
<name>DKG App</name>
<description>
An app that allows uploading their random images they take to our facebook website!
</description>
<author href ="http://www.xxxxxxxx.com" email ="mail@xxxxxxxx.com">
David
</author>
<gap:splash src="splash.png" />
<icon src="icon.png" gap:role="default" />
<feature name="http://api.phonegap.com/1.0/network" />
<feature name="http://api.phonegap.com/1.0/camera"/>
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/media"/>
<preference name="android-minSdkVersion" value="7" />
<preference name="orientation" value="portrait" />
<preference name="target-device" value="universal" />
</widget>
我是否遗漏了一些必要的东西才能让它工作而不是每次都崩溃?
谢谢!
【问题讨论】:
-
您是否在日志中看到任何错误 (
adb logcat)?? -
@dhaval: 我不知道如何使用 adb logcat...?
-
如果您使用 Eclipse,只需打开
DDMS透视图,您应该会看到所有消息。如果是内存问题,请按照西蒙下面提到的内容进行操作。 -
好的,这是日志文件...希望对您有所帮助! pastebin.com/fDxRMpYe
-
你能把你更新的源代码放到 pastebin 里吗?还有你用的是哪个安卓版本??
标签: javascript android html cordova phonegap-plugins