Плагин камеры не работает в сборке PhoneGap для Android

Я создаю приложение PhoneGap. Я установил приложение камеры с помощью «плагина phonegap add cordova-plugin-camera». Он отлично работает в приложении phonegap, но после успешной сборки и загрузки его в сборку phonegap ни одна из этих кнопок не работает на моем телефоне Android. Я публикую свой индекс, конфигурацию и манифест ниже. Спасибо за помощь.

Индекс.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>

Конфиг.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="[email protected]" 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>

person Engin Erdoğan    schedule 15.11.2017    source источник


Ответы (2)


Я использовал более новые версии плагинов. Я поменял их на более старые версии и теперь все работает нормально.

<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" />
person Engin Erdoğan    schedule 15.11.2017

У меня была аналогичная проблема на Android с версией Phonegap 7.0.1 и камерой Cordova-plugin-camera. Он работал, как и ожидалось, на iOS. Обновление плагина до более старой версии решило проблему. Спасибо

person Vik    schedule 17.11.2017
comment
В какой версии вы изменили и это? - person Ralpharoo; 01.02.2018
comment
Я изменил его на cli-6.5.0 - person Vik; 02.02.2018