Cant find the printer


#1

I’m new in hybrid apps development. I develop app that require printing. I installed it on android POS device that have thermal printer embedded on device I failed to detect the printer. Every time I open this page it alert the unavailable message . Help please here are my codes

import { Component } from '@angular/core';
import { NavController, NavParams,AlertController } from 'ionic-angular';
import { Printer, PrintOptions } from '@ionic-native/printer';


@Component({
  selector: 'page-print',
  templateUrl: 'print.html',
})
export class PrintPage {

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public alertCtrl: AlertController,
    public printer: Printer) {
    this.printer.isAvailable().then(value => {
      this.showAlert("isAvailable", value);

    }).catch(error => {
      this.showAlert("ERROR",error);
    });

  }


print(){
          this.printer.check().then(data=>{
            this.showAlert('Check',data);
            },error =>{
            this.showAlert('Check Failed',error);
          });
  }

  showAlert(title, message) {
    let alert = this.alertCtrl.create({
      title: title,
      subTitle: JSON.stringify(message),
      buttons: ['OK']
    });
    alert.present();
  }
}

#2

You should really wait for Platform.ready before doing anything with native plugins.


#3
print(){

      this.platform.ready().then(success =>{
        this.printer.check().then(data=>{
            this.showAlert('Check',data);
            },error =>{
            this.showAlert('Check Failed',error);
          });
      },
      error=>{
        this.showAlert('Platform Not Ready',error);
      })
  }

I add platform.ready() but it still excute the error block of returned promise.


#4

Is the printer available and usable in other apps?

Also, what is in error?


#5

Yes there is app using the printer and it is printing
Error in json

{ "__zone_symbol__currentTask":{"type":"microTask","state":"notScheduled","source":"Promise.then","zone":"angular","cancelFn":null,"runCount":0}}


#6

This doesn’t look right.

Please post your updated code again.


#7
import { Component } from '@angular/core';
import { NavController, NavParams,AlertController,Platform } from 'ionic-angular';
import { Printer, PrintOptions } from '@ionic-native/printer';


@Component({
  selector: 'page-print',
  templateUrl: 'print.html',
})
export class PrintPage {

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public alertCtrl: AlertController,
    public printer: Printer,
    public platform: Platform) {
    
  }


  print(){

      this.platform.ready().then(success =>{
        this.printer.check().then(data=>{
            this.showAlert('Check',data);
            },error =>{
            this.showAlert('Check Failed',error);
          });
      },
      error=>{
        this.showAlert('Platform Not Ready',error);
      });
  }

  showAlert(title, message) {
    let alert = this.alertCtrl.create({
      title: title,
      subTitle: JSON.stringify(message),
      buttons: ['OK']
    });
    alert.present();
  }

}

Updated codes


#9

Why did you change from isAvailable()?

Do you have other printers you could test with?

If you don’t get a better answer, try to use the Cordova plugin directly.


#10

Now the service is available but how can i pick the embedded printer on my device so as I can print on the device.

this is picture of my device


#11

How did you fix it?

Is the embedded printer available in other apps?

(You should probably create a new topic for “how can i pick the embedded printer on my device” so these two different questions don’t get mixed with each other)


#12

Hi,
I have encountered the same error that printer available check failed. Did you finally fix your problem? Can you offer some help?