android - Ionic 2 camera not working on phone -


i relatively new ionic 2, cordova & mobile. followed sample app build simple camera app. similar code in couple of other questions. running on android phone, camera takes picture no image displayed. "takepicture fired" log entry displays no further log entries. there missing permission issue? can't understand why not seeing log entry.

relevant code:

mypage.html

<button ion-button block color="primary" (click)="takepicture()">take   picture</button>   ...  <img [src]="base64image" *ngif="base64image" /> 

mypage.ts

export class mypage {    public base64image: string;    constructor(public navctrl: navcontroller) { }      takepicture() {     console.log("takepicture fired.");     camera.getpicture({       destinationtype: camera.destinationtype.data_url,       sourcetype: camera.picturesourcetype.camera,       encodingtype: camera.encodingtype.jpeg,       targetwidth: 1000,       targetheight: 1000     }).then((imagedata) => {       // imagedata base64 encoded string       this.base64image = "data:image/jpeg;base64," + imagedata;       if (this.base64image) {         console.log("base64image = " + this.base64image);       }       else {         console.log("base64image = null");       }     }, (err) => {       console.log("an error occurred.");       console.error(err);     });     }); 

step 1: in class.ts

import { camera } 'ionic-native'; 

step 2: html

<img [src]="base64image" *ngif="base64image" (click)="captureimage()"/> 

step 3:

captureimage(){        camera.getpicture({                 quality: 100,                 savetophotoalbum: true,                 destinationtype: camera.destinationtype.file_uri,                 sourcetype: camera.picturesourcetype.camera,                 allowedit: true,                 correctorientation: false                 })                .then((result) => {                   this.base64image = result;                   console.log('image uri: ' + this.base64image);                }, (error) => {                 console.log("error -> " + json.stringify(error));             }); } 

it's working fine...

cheers!


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -