Камера работает, когда я набираю команду «ioni c cordova run browser --tab» и загружаю данные в firebase. Теперь я сделал android -apk, я могу открыть камеру, но изображение не сохраняется в переменной. Как заставить ее работать в android?
Код, который я написал:
import { Component } from '@angular/core';
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
import { NavController } from '@ionic/angular';
import * as firebase from 'firebase';
import { environment } from '../../environments/environment';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
clickedImage: string;
name;
selectedPhoto;
plantName;
location;
options: CameraOptions = {
quality: 200,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
};
constructor(private camera: Camera) {
firebase.initializeApp(environment.firebaseConfig);
this.name = "";
this.plantName = "";
this.location = "";
this.selectedPhoto = "";
}
captureImage() {
const options: CameraOptions = {
quality: 200,
targetHeight: 500,
targetWidth: 500,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
};
this.camera.getPicture(options).then((imageData) => {
console.log(this.name, this.plantName, this.selectedPhoto, this.location);
this.selectedPhoto = this.dataURItoBlob('data:image/jpeg;base64,' + imageData);
console.log(this.name, this.plantName, this.selectedPhoto, this.location);
}, (err) => {
console.log('error', err);
});
}
dataURItoBlob(dataURI) {
let binary = atob(dataURI.split(',')[1]);
let array = [];
for (let i = 0; i < binary.length; i++) {
array.push(binary.charCodeAt(i));
}
return new Blob([new Uint8Array(array)], { type: 'image/jpeg' });
};
upload() {
if (this.selectedPhoto) {
let now_date = new Date();
let a = now_date.getTime();
var uploadTask = firebase.storage().ref().child(this.plantName + '/' + this.name + '/' + this.location + a + '.png')
.put(this.selectedPhoto);
}
}
submit() {
console.log(this.name, this.plantName, this.selectedPhoto, this.location);
// this.upload();
if (this.name != "" && this.plantName != "" && this.selectedPhoto != "" && this.location != "") {
this.upload();
alert("Submitted Successfully");
this.name = "";
this.plantName = "";
this.location = "";
this.selectedPhoto = "";
return;
} else {
alert("All values are not entered");
}
}
}
Пожалуйста, помогите заставить камеру работать в приложении android.