[英]DevExtreme/Phonegap camera plugin: “Cannot read propetry 'getPicture' of undefined”
[英]PhoneGap Camera , Cannot read property 'getPicture' of undefined
我想讓Camera API在我的PhoneGap android應用程序中工作,但我一直收到這個錯誤
“無法讀取未定義的屬性'getPicture'”。
現在我已經在整個網絡上檢查了StackOverflow和教程的無數答案,並嘗試了所有的答案(沒有運氣),我似乎無法找到問題。
這是調用該函數的按鈕
<button type="button" class="btn btn-primary" ng-click="getPic()">Camera</button>
這是處理相機的控制器
myApp.controller('EditProfileCtrl', function ($scope, $http, navigateFactory) {
$scope.getPic = function () {
navigator.camera.getPicture(onSuccess, onFail, {
quality: 60,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: 1
});
function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}
function onFail(message) {
alert('Failed beause' + message);
}
};
});
如果需要任何其他信息,請發表評論。 任何和所有的幫助將非常感激。
編輯:所以在遵循Aravin的建議之后我添加了<script src="cordova.js"></script>
現在它至少看起來正在發生什么,但現在我在我的eclipse logcat中得到這些錯誤:
I / System.out(3871):添加插件時出錯org.apache.cordova.CameraLauncher D / PluginManager(3871):exec()調用未知插件:相機
總的工作在下面..
你需要在你的html頁面中編寫所有代碼。
<body>
<div data-role="page">
<script type="text/javascript">
function getPhotoFromCamera() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
quality: 50,
sourceType: navigator.camera.PictureSourceType.CAMERA,
destinationType: navigator.camera.DestinationType.DATA_URL,
});
}
function onPhotoDataSuccess(imageData){
var image = document.getElementById('image');
image.style.display = 'block';
image.src = "data:image/jpeg;base64,"+imageData;
}
function getPhotoFromAlbum(){
navigator.camera.getPicture(onPhotoURISuccess, onFail,{
quality: 50,
sourceType: navigator.camera.PictureSourceType.SAVEDPHOTOALBUM,
destinationType: navigator.camera.DestinationType.FILE_URI
});
}
function onPhotoURISuccess(imageURI){
var image = document.getElementById('image');
image.style.display = 'block';
image.src = imageURI;
}
function onFail(message){
alert('Failed because:' + message);
}
</script>
<div data-role="header" style="height:36px;">
<h1>Write New</h1>
<a href="#" data-icon="arrow-l" data-rel="back">Back</a>
</div>
<button onclick="getPhotoFromCamera();">Launch Camera</button>
<button onclick="getPhotoFromAlbum();">Goto Picture Gallery</button>
<div>
<img id="image" style="display:none;width;290px;height:210px;" src = ""/>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
</body>
所以在嘗試了所有的事情之后沒有成功我做了這個解決了問題(不知道如何)......
刪除插件,構建,添加插件,構建
和魔術!
如果您正在使用TFS,請記得在安裝插件之前檢查編輯“fetch.json”,否則它將在安裝中失敗。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.