Camera Plugin无法在PhoneGap Build for Android上运行

时间:2017-11-15 08:32:47

标签: android cordova phonegap-plugins phonegap-build phonegap

我正在创建一个PhoneGap应用。我用“phonegap插件添加cordova-plugin-camera”安装了相机应用程序。它在phonegap应用程序中工作正常,但在我成功构建并将其上传到phonegap构建后,这些按钮都没有在我的Android手机上运行。我在下面发布我的索引,配置和清单。谢谢你的帮助。

Index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link rel="stylesheet" href="jq/jquery.mobile-1.4.5.css" />
<script type="text/javascript" src="cordova.js"></script>
<script src="jq/jquery-3.2.1.js"></script>
<script src="jq/jquery.mobile-1.4.5.js"></script>
<title>Blank App</title>
<script type="text/javascript" charset="utf-8">
var pictureSource;
var destinationType;

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 = "data:image/jpeg;base64," + imageData;
}

function onPhotoURISuccess(imageURI) {
alert("inside large image")
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.src = imageURI;
}

function capturePhoto() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
destinationType: destinationType.DATA_URL });
}

function capturePhotoEdit() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail,
{ quality: 20, allowEdit: true,
destinationType: destinationType.DATA_URL });
}

function getPhoto(source) {
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
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="capturePhotoEdit();">Capture Editable Photo</button> <br>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
<button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</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 id="com.phonegap.helloworld" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name>App005</name>
<description>
    A blank PhoneGap app.
</description>
<author email="support@phonegap.com" href="http://phonegap.com">
    PhoneGap Team
</author>
<content src="index.html" />
<access origin="*" />
<engine name="android" spec="~6.3.0" />
<plugin name="cordova-plugin-camera" spec="~3.0.0" />
</widget>

的AndroidManifest.xml

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.phonegap.helloworld" 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="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" 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>
<provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
</provider>
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

2 个答案:

答案 0 :(得分:0)

我使用的是较新版本的插件。我将它们改为旧版本,现在一切正常。

<plugin name="cordova-plugin-camera" spec="2.4.1" />
<plugin name="cordova-plugin-compat" spec="1.2.0" />
<plugin name="cordova-plugin-whitelist" spec="1.3.3" />
<plugin name="cordova-plugin-file" spec="4.3.1" />
<plugin name="cordova-plugin-file-transfer" spec="1.6.1" />
<plugin name="cordova-plugin-media-capture" spec="1.4.3" />

答案 1 :(得分:0)

我在Android上使用Phonegap 7.0.1版和cordova-plugin-camera遇到了类似的问题。它在iOS上按预期工作。将插件更新到旧版本已修复此问题。感谢