mjs
January 25, 2016, 7:46am
1
Hello guys,
I wanna use only front camera, i used -> cordova plugin add cordova-plugin-camera
When i change value of cameraDirection to 1 or Camera.Direction.BACK both not working.
Any sugestion guys to solve that problem ?
Here is the code :
$scope.takeCamera = function(){
var optionsCamera = {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
targetWidth: 50,
cameraDirection : 1,
encodingType : Camera.EncodingType.JPEG
};
var onAfterCaptureCamera = function(imageData){
alert('berhasil');
navigator.camera.cleanup(function(){}, function(){});
};
var onFailCamera = function(message){
alert(JSON.stringify(message));
};
navigator.camera.getPicture(onAfterCaptureCamera, onFailCamera, optionsCamera);
}
1 Like
What’s not working? Have you looked at a console.log?
mjs
January 25, 2016, 8:49am
3
when i run takeCamera function, camera work well but always show back camera. Then click change change camera.
What i wanted is when i run takeCamera function, show front camera at the first time
Aster
March 16, 2016, 8:40am
4
Hi @mjs ,
Any leads on this. I am also not able to get it working for android.
Hi @Aster !
Had the same issue month ago…
After several trys with no luck and a lot of reading i found this oneliner in the cordova docs under the Android quirks section:
Any cameraDirection value results in a back-facing photo.
Here is the link: cordova-plugin-camera - npm
I also found the related issue for frontfacing Camera Option resolved with a “wont fix” here:
https://issues.apache.org/jira/browse/CB-1690
The author also mentioned that it is possible for the User to toggle the Camera direction. I think this is not the case. Will try it on latest Android tomorrow…
Let me know in you can find the toggle option.
The toggle Option is (as expected) not there…
Is there any body that can make front facing camera working on android??
I can’t believe that such standard functionality is not working for such a long time?!?!?
Are there other plugins where i can use the front facing camera?
THX
1 Like
Any solutions yet , guys?
I want to open the camera from the start for selfie
Won’t cameraDirection: this.camera.Direction.FRONT solve it? going to check now
Worked for me…
I am firing the camera from constructor
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Camera, CameraOptions } from '@ionic-native/camera';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public base64Image: string;
constructor(public navCtrl: NavController,private camera: Camera) {
this.takePhoto(this.camera.PictureSourceType.CAMERA)
}
takePhoto(sourceType:number) {
const options: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
correctOrientation: true,
sourceType:sourceType,
cameraDirection: this.camera.Direction.FRONT
}
this.camera.getPicture(options).then((imageData) => {
let base64Image = 'data:image/jpeg;base64,' + imageData;
}, (err) => {
// Handle error
});
}
}
Don’t forget camera at app.module.ts
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
**Camera**
]
abhibly
November 12, 2019, 1:37pm
11
On what device you tested?
not working back camera only opened