我想创建一个简单的"拍照"带有 Cordova 2.9 的Android应用程序,只需一个按钮即可启动getPicture()API,但单击我创建的按钮时没有任何反应。 这是我在index文件夹中的index.html文件的代码:
<!DOCTYPE html>
<html>
<head>
<title>Take a photo</title>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener(“deviceready”,onDeviceReady,false);
function onDeviceReady() {
}
// Called when a photo is successfully retrieved
//
function onPhotoSuccess(imageData) {
var myImage = document.getElementById(‘myImage’);
myImage.style.display = ‘block’;
myImage.src = “data:image/jpeg;base64,” + imageData;}
function capturePhoto() {
navigator.camera.getPicture(onPhotoSuccess, onPhotoFail, { quality: 50 });
}
function onPhotoFail(message) {
alert(‘Failed because: ‘ + message);
}
</script>
</head>
<body>
<button onclick=”capturePhoto();”>Capture Photo</button> <br>
<img style=”display:none;width:60px;height:60px;” id=”myImage” src=”” />
</body>
</html>
这是我的config.xml文件:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.localdb.com" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Localdb</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<access origin="*" />
<feature name="Camera">
<param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
</feature>
</widget>
和我的AndroidManifest.xml文件:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.localdb.com" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="CordovaApp" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
请您告诉我文件中是否遗漏了任何事先感谢您!