giorgiofellipe / cordova-plugin-datecs-printer

Cordova plugin to print on Mobile Bluetooth ESC/POS Printers - Tested on Datecs DPP-250 Printer
MIT License
73 stars 60 forks source link

Plugin not working on Android 4.1.2 #43

Closed aupareal closed 7 years ago

aupareal commented 7 years ago

Hello, The plugin not working on Android 4.1.2. Any suggestion ? Thank you.

giorgiofellipe commented 7 years ago

Not enough info. Be more specific, it is working for you in another versions? What did you try to?

aupareal commented 7 years ago

First of all, thank you for your quick response. The plugin working fine on Android 5.0 or above. The first function "window.DatecsPrinter.listBluetoothDevices" lock the APP. My code:

    window.DatecsPrinter.listBluetoothDevices(
        function(devices) {

            var impresora = 0;
            var bt = 0;
            for (var i = 0; i < devices.length; i++) {
                if ( devices[i].name.includes("DPP-") ) {
                    bt = i;
                    impresora = 1;
                    break;
                } else if ( devices[i].name.includes("Printer") ) {
                    bt = i;
                    impresora = 1;
                    break;
                }
            }   

            if ( impresora == 0 ) {
                app.showNotification('Impresora no reconocida');
            }    

            app.showNotification(devices[bt].name);

            window.DatecsPrinter.connect(devices[bt].address,
                function() {

                    window.DatecsPrinter.printText('Hola mundo', 'ISO-8859-1');
                    window.DatecsPrinter.disconnect();
                },
                function() {
                    alert(JSON.stringify(error));
                }
            );
            window.DatecsPrinter.disconnect();
        },
        function(error) {
            alert('error');
            alert(JSON.stringify(error));
        }
    );  

giorgiofellipe commented 7 years ago

Lets break this into baby steps to easily find what's going wrong. I guess it's some implementation issue, cuz I can confirm it's working well on Android 4.1.2. First of all, be sure to only have the printer paired to the device. Then try the example, I'll paste here:

window.DatecsPrinter.listBluetoothDevices(
  function (devices) {
    window.DatecsPrinter.connect(devices[0].address, 
      function() {
        alert("connected!");
        printSomeTestText();
      },
      function() {
        alert(JSON.stringify(error));
      }
    );
  },
  function (error) {
    alert(JSON.stringify(error));
  }
);

function printSomeTestText() {
  window.DatecsPrinter.printText("Print Test!", 'ISO-8859-1', 
    function() {
      alert("finished!");
    }
  );
}
aupareal commented 7 years ago

I'm very sorry, but not working. If the bluetooth is down, it show the error correctly. However, if the bluetooth is up does nothing. Thank you.

giorgiofellipe commented 7 years ago

what is the return of listBluetoothDevices?

aupareal commented 7 years ago

Nothing, no error too. Tomorrow I will prove with other mobile.

giorgiofellipe commented 7 years ago

Closing due to long time without activity. If necessary I'll reopen.