我们尝试使用phonegap从Android设备打开相机,但无法做到这一点。能帮助我们吗。
以下是编写的代码。
<div>
<input class="camerabutton" id="btnCamera" value="open camera" type="button" height="100" width="100" />
</div>
<script type="text/javascript" src="js/cordova.js"></script>
<script type="text/javascript" src="js/cordova_plugins.js"></script>
<script type="text/javascript" src="js/framework7.js"></script>
<script type="text/javascript">
var myApp = new Framework7();
// Export selectors engine
var $$ = Dom7;
$$('.camerabutton').on('click', function () {
navigator.camera.getPicture(onSuccess, onFail, {
quality: 50
});
function onSuccess(imageData) {
alert("test");
}
function onFail(message) {
alert('Failed because: ' + message);
}
});
</script>
Config.xml文件(给定所有权限)
<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"/>
AndroidManifest.xml文件
<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.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
如果上述代码中存在任何问题或需要添加内容,请告诉我们。
答案 0 :(得分:1)
您是否尝试过添加质量旁边的选项:
destinationType: Camera.DestinationType.DATA_URL
在我更改之前,File_uri的默认设置对我不起作用。
此外,我的cordova相机插件不知何故死了一次。卸载插件并重新安装即可修复相机问题。
答案 1 :(得分:1)
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.test" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>test</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="Contacts.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<feature name="Contacts">
<param name="android-package" value="org.apache.cordova.contacts.ContactManager" />
</feature>
<feature name="Camera">
<param name="android-package" value="org.apache.cordova.CameraLauncher" />
</feature>
</widget>