【发布时间】:2015-06-07 16:46:56
【问题描述】:
我开发了一个应用程序来测试在 Android 手机中打开的相机。我遵循了科尔多瓦相机 API 文档。我的代码在模拟器中运行良好且完美,但在手机中打开相机时无法打开。
这是我的代码:config.xml
<?xml version="1.0" encoding="utf-8"?>
<widget xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:vs="http://schemas.microsoft.com/appx/2014/htmlapps" id="io.cordova.CameraTest" version="1.0.0" xmlns="http://www.w3.org/ns/widgets">
<name>CameraTest</name>
<description>A blank project that uses Apache Cordova to help you build an app that targets multiple mobile platforms: Android, iOS, Windows, and Windows Phone.</description>
<author href="http://cordova.io" email="dev@cordova.apache.org">Apache Cordova Team </author>
<content src="index.html" />
<access origin="*" />
<preference name="SplashScreen" value="screen" />
<preference name="windows-target-version" value="8.0" />
<preference name="windows-phone-target-version" value="8.1" />
<vs:plugin name="org.apache.cordova.camera" version="0.3.2" />
<vs:plugin name="org.apache.cordova.dialogs" version="0.2.10" />
<feature name="http://api.phonegap.com/1.0/device" />
<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"/>
<feature name="http://api.phonegap.com/1.0/network"/>
<vs:platformSpecificValues />
</widget>
js代码:
document.addEventListener( 'deviceready', onDeviceReady.bind( this ), false );
function onDeviceReady() {
// Handle the Cordova pause and resume events
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
document.addEventListener( 'pause', onPause.bind( this ), false );
document.addEventListener( 'resume', onResume.bind( this ), false );
// TODO: Cordova has been loaded. Perform any initialization that requires Cordova here.
};
脚本:
<script src="cordova.js"></script>
<script>
var pictureSource;
var destinationType;
function opencam() {
navigator.camera.getPicture(onsucess, onfail, {
quality: 50,
destinationType: destinationType.DATA_URL,
allowEdit: true,
targetWidth: 100,
targetHeight: 100,
saveToPhotoAlbum: false
});
}
function onsucess(imageData) {
debugger;
}
function onfail(message) {
alert("Error: " + message);
debugger;
}
</script>
它在波纹模拟器中工作正常,但是当我安装在移动设备中时,相机完全打开了。
注意:我的解决方案中没有 androidmanifest.xml 文件。
【问题讨论】:
-
看不出为什么它在模拟器中工作正常,我看不出你在哪里调用函数'opencam'?
标签: android apache cordova jquery-mobile android-camera