I have created to Capture video app with Ionic.
I already installed ionic 2.2.0
And I have installed media capture plugin as following command.
npm install --save @ionic-native/media-capture
And I have written the code as following.
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { MediaCapture, MediaFile, CaptureError, CaptureVideoOptions } from '@ionic-native/media-capture';
import { Transfer, TransferObject } from '@ionic-native/transfer';
import { NativeStorage } from '@ionic-native/native-storage';
import { Diagnostic } from '@ionic-native/diagnostic';
@Component({
selector: 'page-camera',
templateUrl: 'camera.html'
})
export class CameraPage {
constructor(public navCtrl: NavController, private nativeStorage: NativeStorage, private mediaCapture: MediaCapture, private diagnostic: Diagnostic) {
this.transfer = new Transfer();
this.diagnostic = new Diagnostic();
this.checkPermissions();
}
/**
* Camera Permission
*/
checkPermissions(){
this.diagnostic.isCameraAuthorized().then((authorized) => {
if(authorized)
this.recordVideo();
else {
this.diagnostic.requestCameraAuthorization().then(_status => {
if(_status == this.diagnostic.permissionStatus.GRANTED){
this.recordVideo();
} else {
// Permissions not granted
// Therefore, create and present toast
this.diagnostic.isCameraPresent().then(isCamera => {
alert('Camera permission : ' + this.diagnostic.permission.CAMERA);
alert('Is Camera : ' + isCamera);
this.recordVideo();
});
}
});
}
});
}
recordVideo(){
... ... ...
}
In this case, the app doesn’t work for using camera( for capturing video ).
How can I do?
In fact, I have already implemented capturing video.
At that time, I used that command for install media capture plugin.
ionic cordova plugin add cordova-plugin-media-capture
And I implemented as following.
import { Diagnostic } from 'ionic-native';
... ... ...
checkPermissions(){
Diagnostic.isCameraAuthorized().then((authorized) => {
if(authorized)
this.recordVideo();
else {
Diagnostic.requestCameraAuthorization().then(_status => {
if(_status == Diagnostic.permissionStatus.GRANTED){
this.recordVideo();
} else {
// Permissions not granted
// Therefore, create and present toast
Diagnostic.isCameraPresent().then(isCamera => {
alert('Camera permission : ' + Diagnostic.permission.CAMERA);
alert('Is Camera : ' + isCamera);
this.recordVideo();
});
}
});
}
});
}
And the app works using this checkPermissions method.
Why I can’t check camera permission now?