Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kindly contact me #1

Open
OutsourceNow opened this issue Mar 20, 2019 · 12 comments
Open

Kindly contact me #1

OutsourceNow opened this issue Mar 20, 2019 · 12 comments

Comments

@OutsourceNow
Copy link

Kindly contact me i need help with aidl communication with printer service for a handheld pos device like the one you worked on for sunmi. I have followed you code in that plugin but doesent work for me;

error: [app-scripts] [13:59:55] console.log: Attempt to invoke interface method 'void [app-scripts] com.iposprinter.iposprinterservice.IPosPrinterService.printerInit(com.iposprinter.iposprinterservice.IPosPrinterCallback)' [app-scripts] on a null object reference

you can check the plugin here and kindly advise: https://github.com/OutsourceNow/cordova-ocom-q1-printer
it seems i cant get the service object.
if you can help please email me: [email protected]

@Hackbard
Copy link

Hi, i got the same Error here.
After an reboot it works unti something went wrong with the printer. Like empty Paper and refill.
Have you found an solution?

@Mukopaje
Copy link

Hi, @Hackbard what device are you using? I have integrated a few devices through SDK in between but for that specific issue, I ended up using the Bluetooth connection to the onboard printer as there was such provision. The SDK connection was too slow during printing. Let me know what device you are using, maybe I can help.

@Hackbard
Copy link

I'm using POS-Terminal Android 8,1 as you find here
https://m.de.aliexpress.com/item/4001098397158.html

@Mukopaje
Copy link

Usually, the handheld POS Terminal would come with print via Bluetooth mechanism, Could you confirm that's not the case with that device. Because if it does have Bluetooth support on the printer then you can trying to use that approach and just send data to the printer using ESC Command. If you are using Ionic for your app there is a number of libraries you could use to connect to the printer via Bluetooth. Check the Bluetooth page on the device if the printer is one of the paired devices.

@Hackbard
Copy link

Ok, sounds good. You have an advice / tutorial to help me? I'm using clean Java 😁

@Mukopaje
Copy link

Ok, sounds good. Do you have any advice/tutorials to help me? I'm using clean Java 😁

Could you confirm first that you have something like that under Bluetooth on the device
BT-Printer

@Hackbard
Copy link

Yes exactly like that!

@Hackbard
Copy link

Hackbard commented Sep 1, 2021

So yes, i got the Bluetooth connection to the Device.

@Mukopaje
Copy link

Mukopaje commented Sep 1, 2021

So yes, i got the Bluetooth connection to the Device.

Have you managed to connect to the printer in your code? What do you have so far if you haven't?

@Hackbard
Copy link

Hackbard commented Sep 1, 2021

using this:
But after some time the service / connection is gone
`
package net.mycompany.iposprinter;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
import android.widget.Toast;

import com.iposprinter.iposprinterservice.IPosPrinterCallback;
import com.iposprinter.iposprinterservice.IPosPrinterService;

public class IposPrinter {

private static final String TAG                 = "IPOSPRINTER";
private boolean isConnected = false;
private IPosPrinterService mIPosPrinterService = null;
private IPosPrinterCallback callback = null;
private static IposPrinter iposPrinterInstance = null;
private int printerStatus = 0;

private com.iposprinter.printertestdemo.Utils.HandlerUtils.MyHandler handler;

private final String  PRINTER_NORMAL_ACTION = "com.iposprinter.iposprinterservice.NORMAL_ACTION";
private final String  PRINTER_PAPERLESS_ACTION = "com.iposprinter.iposprinterservice.PAPERLESS_ACTION";
private final String  PRINTER_PAPEREXISTS_ACTION = "com.iposprinter.iposprinterservice.PAPEREXISTS_ACTION";
private final String  PRINTER_THP_HIGHTEMP_ACTION = "com.iposprinter.iposprinterservice.THP_HIGHTEMP_ACTION";
private final String  PRINTER_THP_NORMALTEMP_ACTION = "com.iposprinter.iposprinterservice.THP_NORMALTEMP_ACTION";
private final String  PRINTER_MOTOR_HIGHTEMP_ACTION = "com.iposprinter.iposprinterservice.MOTOR_HIGHTEMP_ACTION";
private final String  PRINTER_BUSY_ACTION = "com.iposprinter.iposprinterservice.BUSY_ACTION";
private final String  PRINTER_CURRENT_TASK_PRINT_COMPLETE_ACTION = "com.iposprinter.iposprinterservice.CURRENT_TASK_PRINT_COMPLETE_ACTION";

private final int MSG_TEST                               = 1;
private final int MSG_IS_NORMAL                          = 2;
private final int MSG_IS_BUSY                            = 3;
private final int MSG_PAPER_LESS                         = 4;
private final int MSG_PAPER_EXISTS                       = 5;
private final int MSG_THP_HIGH_TEMP                      = 6;
private final int MSG_THP_TEMP_NORMAL                    = 7;
private final int MSG_MOTOR_HIGH_TEMP                    = 8;
private final int MSG_MOTOR_HIGH_TEMP_INIT_PRINTER       = 9;
private final int MSG_CURRENT_TASK_PRINT_COMPLETE     = 10;

private final int PRINTER_NORMAL = 0;
private final int PRINTER_PAPERLESS = 1;
private final int PRINTER_THP_HIGH_TEMPERATURE = 2;
private final int PRINTER_MOTOR_HIGH_TEMPERATURE = 3;
private final int PRINTER_IS_BUSY = 4;
private final int PRINTER_ERROR_UNKNOWN = 5;

private ServiceConnection serviceConnection = new ServiceConnection() {
    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        IposPrinter.getInstance().setMIPosPrinterService(IPosPrinterService.Stub.asInterface(service));
        isConnected = true;
        Log.i("IposPrinter", "Binding Success");
    }

    @Override
    public void onServiceDisconnected(ComponentName name) {
        IposPrinter.getInstance().setMIPosPrinterService(null);
        isConnected = false;
        Log.i("IposPrinter", "binding failed");
    }
};

private BroadcastReceiver IPosPrinterStatusListener = new BroadcastReceiver(){
    @Override
    public void onReceive(Context context, Intent intent){
        String action = intent.getAction();
        if(action == null)
        {
            Log.d(TAG,"IPosPrinterStatusListener onReceive action = null");
            return;
        }
        Log.d(TAG,"IPosPrinterStatusListener action = "+action);
        if(action.equals(PRINTER_NORMAL_ACTION))
        {
            handler.sendEmptyMessageDelayed(MSG_IS_NORMAL,0);
        }
        else if (action.equals(PRINTER_PAPERLESS_ACTION))
        {
            handler.sendEmptyMessageDelayed(MSG_PAPER_LESS,0);
        }
        else if (action.equals(PRINTER_BUSY_ACTION))
        {
            handler.sendEmptyMessageDelayed(MSG_IS_BUSY,0);
        }
        else if (action.equals(PRINTER_PAPEREXISTS_ACTION))
        {
            handler.sendEmptyMessageDelayed(MSG_PAPER_EXISTS,0);
        }
        else if (action.equals(PRINTER_THP_HIGHTEMP_ACTION))
        {
            handler.sendEmptyMessageDelayed(MSG_THP_HIGH_TEMP,0);
        }
        else if (action.equals(PRINTER_THP_NORMALTEMP_ACTION))
        {
            handler.sendEmptyMessageDelayed(MSG_THP_TEMP_NORMAL,0);
        }
        else if (action.equals(PRINTER_MOTOR_HIGHTEMP_ACTION))  //此时当前任务会继续打印,完成当前任务后,请等待2分钟以上时间,继续下一个打印任务
        {
            handler.sendEmptyMessageDelayed(MSG_MOTOR_HIGH_TEMP,0);
        }
        else if(action.equals(PRINTER_CURRENT_TASK_PRINT_COMPLETE_ACTION))
        {
            handler.sendEmptyMessageDelayed(MSG_CURRENT_TASK_PRINT_COMPLETE,0);
        }
        else
        {
            handler.sendEmptyMessageDelayed(MSG_TEST,0);
        }
    }
};

private com.iposprinter.printertestdemo.Utils.HandlerUtils.IHandlerIntent iHandlerIntent = new com.iposprinter.printertestdemo.Utils.HandlerUtils.IHandlerIntent()
{
    @Override
    public void handlerIntent(Message msg)
    {
        switch (msg.what)
        {
            case MSG_TEST:
                break;
            case MSG_IS_NORMAL:
                if(getPrinterStatus() == PRINTER_NORMAL)
                {
                   // is normal
                }
                break;
            case MSG_IS_BUSY:
                Log.i(TAG, "PRINTER IS WORKING");
                //Toast.makeText(this, R.string.printer_is_working, Toast.LENGTH_SHORT).show();
                break;
            case MSG_PAPER_LESS:
                Log.i(TAG, "The printer is out of paper");
                ///Toast.makeText(this, R.string.out_of_paper, Toast.LENGTH_SHORT).show();
                break;
            case MSG_PAPER_EXISTS:
                Log.i(TAG, "The printer paper is ready");
                //Toast.makeText(this, R.string.exists_paper, Toast.LENGTH_SHORT).show();
                break;
            case MSG_THP_HIGH_TEMP:
                Log.i(TAG, "Printer high temperature alarm");
                //Toast.makeText(this, R.string.printer_high_temp_alarm, Toast.LENGTH_SHORT).show();
                break;
            case MSG_MOTOR_HIGH_TEMP:
                Log.i(TAG, "Motor high temperature alarm");
                //Toast.makeText(this, R.string.motor_high_temp_alarm, Toast.LENGTH_SHORT).show();
                handler.sendEmptyMessageDelayed(MSG_MOTOR_HIGH_TEMP_INIT_PRINTER, 180000);  //马达高温报警,等待3分钟后复位打印机
                break;
            case MSG_MOTOR_HIGH_TEMP_INIT_PRINTER:
                printerInit();
                break;
            case MSG_CURRENT_TASK_PRINT_COMPLETE:
                Log.i(TAG, "The print task has been printed");
                //Toast.makeText(this, R.string.printer_current_task_print_complete, Toast.LENGTH_SHORT).show();
                break;
            default:
                break;
        }
    }
};

private IposPrinter(){
    callback = new IPosPrinterCallback.Stub() {

        @Override
        public void onRunResult(final boolean isSuccess) throws RemoteException {
            Log.i(TAG,"result:" + isSuccess + "\n");
        }

        @Override
        public void onReturnString(final String value) throws RemoteException {
            Log.i(TAG,"result:" + value + "\n");
        }
    };

    IntentFilter printerStatusFilter = new IntentFilter();
    printerStatusFilter.addAction(PRINTER_NORMAL_ACTION);
    printerStatusFilter.addAction(PRINTER_PAPERLESS_ACTION);
    printerStatusFilter.addAction(PRINTER_PAPEREXISTS_ACTION);
    printerStatusFilter.addAction(PRINTER_THP_HIGHTEMP_ACTION);
    printerStatusFilter.addAction(PRINTER_THP_NORMALTEMP_ACTION);
    printerStatusFilter.addAction(PRINTER_MOTOR_HIGHTEMP_ACTION);
    printerStatusFilter.addAction(PRINTER_BUSY_ACTION);

    handler = new com.iposprinter.printertestdemo.Utils.HandlerUtils.MyHandler(iHandlerIntent);
    callback = new IPosPrinterCallback.Stub() {
        @Override
        public void onRunResult(final boolean isSuccess) throws RemoteException {
            Log.i(TAG,"result:" + isSuccess + "\n");
        }

        @Override
        public void onReturnString(final String value) throws RemoteException {
            Log.i(TAG,"result:" + value + "\n");
        }
    };
}

public static IposPrinter getInstance(){
    if(iposPrinterInstance == null){
        iposPrinterInstance = new IposPrinter();
    }
    return iposPrinterInstance;
}

public boolean IsConnected(){
    return isConnected;
}

public int getPrinterStatus(){
    Log.i("IPOSPRINTER","***** printerStatus"+printerStatus);
    try{
        printerStatus = mIPosPrinterService.getPrinterStatus();
    }catch (RemoteException e){
        e.printStackTrace();
    }
    Log.i("IPOSPRINTER","#### printerStatus"+printerStatus);
    return  printerStatus;
}

public ServiceConnection getServiceConnection(){
    return serviceConnection;
}

public void setMIPosPrinterService(IPosPrinterService value){
    this.mIPosPrinterService = value;
}

public IPosPrinterService getMIPosPrinterService(){
    return this.mIPosPrinterService;
}

public int testPrint(Bitmap bitmap) {
    this.printerInit();
    // Print images
    try {
        Log.i(TAG, "Start print Data");
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int newWidth = 384;
        Matrix matrix = new Matrix();
        if(width > newWidth) {
            float scaleWidth = (float) newWidth / (float) width;
            matrix.postScale(scaleWidth, 1.0F);
        }

        Bitmap bitmap1 = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
        this.mIPosPrinterService.printBitmap(1, 16, bitmap1, callback);  // 0, 17
        this.mIPosPrinterService.printBlankLines(10, 10, callback);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    int printerStatus = 0;
    try {
        printerStatus = this.mIPosPrinterService.getPrinterStatus();
    } catch (RemoteException e) {
        e.printStackTrace();
    }

    return printerStatus;
}

public void printerInit(){
    try{
        mIPosPrinterService.printerInit(callback);
    }catch (RemoteException e){
        e.printStackTrace();
    }
}

}

`

@Mukopaje
Copy link

Mukopaje commented Sep 2, 2021

using this:
But after some time the service / connection is gone
`
package net.mycompany.iposprinter;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
import android.widget.Toast;

import com.iposprinter.iposprinterservice.IPosPrinterCallback;
import com.iposprinter.iposprinterservice.IPosPrinterService;

public class IposPrinter {

private static final String TAG                 = "IPOSPRINTER";
private boolean isConnected = false;
private IPosPrinterService mIPosPrinterService = null;
private IPosPrinterCallback callback = null;
private static IposPrinter iposPrinterInstance = null;
private int printerStatus = 0;

private com.iposprinter.printertestdemo.Utils.HandlerUtils.MyHandler handler;

private final String  PRINTER_NORMAL_ACTION = "com.iposprinter.iposprinterservice.NORMAL_ACTION";
private final String  PRINTER_PAPERLESS_ACTION = "com.iposprinter.iposprinterservice.PAPERLESS_ACTION";
private final String  PRINTER_PAPEREXISTS_ACTION = "com.iposprinter.iposprinterservice.PAPEREXISTS_ACTION";
private final String  PRINTER_THP_HIGHTEMP_ACTION = "com.iposprinter.iposprinterservice.THP_HIGHTEMP_ACTION";
private final String  PRINTER_THP_NORMALTEMP_ACTION = "com.iposprinter.iposprinterservice.THP_NORMALTEMP_ACTION";
private final String  PRINTER_MOTOR_HIGHTEMP_ACTION = "com.iposprinter.iposprinterservice.MOTOR_HIGHTEMP_ACTION";
private final String  PRINTER_BUSY_ACTION = "com.iposprinter.iposprinterservice.BUSY_ACTION";
private final String  PRINTER_CURRENT_TASK_PRINT_COMPLETE_ACTION = "com.iposprinter.iposprinterservice.CURRENT_TASK_PRINT_COMPLETE_ACTION";

private final int MSG_TEST                               = 1;
private final int MSG_IS_NORMAL                          = 2;
private final int MSG_IS_BUSY                            = 3;
private final int MSG_PAPER_LESS                         = 4;
private final int MSG_PAPER_EXISTS                       = 5;
private final int MSG_THP_HIGH_TEMP                      = 6;
private final int MSG_THP_TEMP_NORMAL                    = 7;
private final int MSG_MOTOR_HIGH_TEMP                    = 8;
private final int MSG_MOTOR_HIGH_TEMP_INIT_PRINTER       = 9;
private final int MSG_CURRENT_TASK_PRINT_COMPLETE     = 10;

private final int PRINTER_NORMAL = 0;
private final int PRINTER_PAPERLESS = 1;
private final int PRINTER_THP_HIGH_TEMPERATURE = 2;
private final int PRINTER_MOTOR_HIGH_TEMPERATURE = 3;
private final int PRINTER_IS_BUSY = 4;
private final int PRINTER_ERROR_UNKNOWN = 5;

private ServiceConnection serviceConnection = new ServiceConnection() {
    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        IposPrinter.getInstance().setMIPosPrinterService(IPosPrinterService.Stub.asInterface(service));
        isConnected = true;
        Log.i("IposPrinter", "Binding Success");
    }

    @Override
    public void onServiceDisconnected(ComponentName name) {
        IposPrinter.getInstance().setMIPosPrinterService(null);
        isConnected = false;
        Log.i("IposPrinter", "binding failed");
    }
};

private BroadcastReceiver IPosPrinterStatusListener = new BroadcastReceiver(){
    @Override
    public void onReceive(Context context, Intent intent){
        String action = intent.getAction();
        if(action == null)
        {
            Log.d(TAG,"IPosPrinterStatusListener onReceive action = null");
            return;
        }
        Log.d(TAG,"IPosPrinterStatusListener action = "+action);
        if(action.equals(PRINTER_NORMAL_ACTION))
        {
            handler.sendEmptyMessageDelayed(MSG_IS_NORMAL,0);
        }
        else if (action.equals(PRINTER_PAPERLESS_ACTION))
        {
            handler.sendEmptyMessageDelayed(MSG_PAPER_LESS,0);
        }
        else if (action.equals(PRINTER_BUSY_ACTION))
        {
            handler.sendEmptyMessageDelayed(MSG_IS_BUSY,0);
        }
        else if (action.equals(PRINTER_PAPEREXISTS_ACTION))
        {
            handler.sendEmptyMessageDelayed(MSG_PAPER_EXISTS,0);
        }
        else if (action.equals(PRINTER_THP_HIGHTEMP_ACTION))
        {
            handler.sendEmptyMessageDelayed(MSG_THP_HIGH_TEMP,0);
        }
        else if (action.equals(PRINTER_THP_NORMALTEMP_ACTION))
        {
            handler.sendEmptyMessageDelayed(MSG_THP_TEMP_NORMAL,0);
        }
        else if (action.equals(PRINTER_MOTOR_HIGHTEMP_ACTION))  //此时当前任务会继续打印,完成当前任务后,请等待2分钟以上时间,继续下一个打印任务
        {
            handler.sendEmptyMessageDelayed(MSG_MOTOR_HIGH_TEMP,0);
        }
        else if(action.equals(PRINTER_CURRENT_TASK_PRINT_COMPLETE_ACTION))
        {
            handler.sendEmptyMessageDelayed(MSG_CURRENT_TASK_PRINT_COMPLETE,0);
        }
        else
        {
            handler.sendEmptyMessageDelayed(MSG_TEST,0);
        }
    }
};

private com.iposprinter.printertestdemo.Utils.HandlerUtils.IHandlerIntent iHandlerIntent = new com.iposprinter.printertestdemo.Utils.HandlerUtils.IHandlerIntent()
{
    @Override
    public void handlerIntent(Message msg)
    {
        switch (msg.what)
        {
            case MSG_TEST:
                break;
            case MSG_IS_NORMAL:
                if(getPrinterStatus() == PRINTER_NORMAL)
                {
                   // is normal
                }
                break;
            case MSG_IS_BUSY:
                Log.i(TAG, "PRINTER IS WORKING");
                //Toast.makeText(this, R.string.printer_is_working, Toast.LENGTH_SHORT).show();
                break;
            case MSG_PAPER_LESS:
                Log.i(TAG, "The printer is out of paper");
                ///Toast.makeText(this, R.string.out_of_paper, Toast.LENGTH_SHORT).show();
                break;
            case MSG_PAPER_EXISTS:
                Log.i(TAG, "The printer paper is ready");
                //Toast.makeText(this, R.string.exists_paper, Toast.LENGTH_SHORT).show();
                break;
            case MSG_THP_HIGH_TEMP:
                Log.i(TAG, "Printer high temperature alarm");
                //Toast.makeText(this, R.string.printer_high_temp_alarm, Toast.LENGTH_SHORT).show();
                break;
            case MSG_MOTOR_HIGH_TEMP:
                Log.i(TAG, "Motor high temperature alarm");
                //Toast.makeText(this, R.string.motor_high_temp_alarm, Toast.LENGTH_SHORT).show();
                handler.sendEmptyMessageDelayed(MSG_MOTOR_HIGH_TEMP_INIT_PRINTER, 180000);  //马达高温报警,等待3分钟后复位打印机
                break;
            case MSG_MOTOR_HIGH_TEMP_INIT_PRINTER:
                printerInit();
                break;
            case MSG_CURRENT_TASK_PRINT_COMPLETE:
                Log.i(TAG, "The print task has been printed");
                //Toast.makeText(this, R.string.printer_current_task_print_complete, Toast.LENGTH_SHORT).show();
                break;
            default:
                break;
        }
    }
};

private IposPrinter(){
    callback = new IPosPrinterCallback.Stub() {

        @Override
        public void onRunResult(final boolean isSuccess) throws RemoteException {
            Log.i(TAG,"result:" + isSuccess + "\n");
        }

        @Override
        public void onReturnString(final String value) throws RemoteException {
            Log.i(TAG,"result:" + value + "\n");
        }
    };

    IntentFilter printerStatusFilter = new IntentFilter();
    printerStatusFilter.addAction(PRINTER_NORMAL_ACTION);
    printerStatusFilter.addAction(PRINTER_PAPERLESS_ACTION);
    printerStatusFilter.addAction(PRINTER_PAPEREXISTS_ACTION);
    printerStatusFilter.addAction(PRINTER_THP_HIGHTEMP_ACTION);
    printerStatusFilter.addAction(PRINTER_THP_NORMALTEMP_ACTION);
    printerStatusFilter.addAction(PRINTER_MOTOR_HIGHTEMP_ACTION);
    printerStatusFilter.addAction(PRINTER_BUSY_ACTION);

    handler = new com.iposprinter.printertestdemo.Utils.HandlerUtils.MyHandler(iHandlerIntent);
    callback = new IPosPrinterCallback.Stub() {
        @Override
        public void onRunResult(final boolean isSuccess) throws RemoteException {
            Log.i(TAG,"result:" + isSuccess + "\n");
        }

        @Override
        public void onReturnString(final String value) throws RemoteException {
            Log.i(TAG,"result:" + value + "\n");
        }
    };
}

public static IposPrinter getInstance(){
    if(iposPrinterInstance == null){
        iposPrinterInstance = new IposPrinter();
    }
    return iposPrinterInstance;
}

public boolean IsConnected(){
    return isConnected;
}

public int getPrinterStatus(){
    Log.i("IPOSPRINTER","***** printerStatus"+printerStatus);
    try{
        printerStatus = mIPosPrinterService.getPrinterStatus();
    }catch (RemoteException e){
        e.printStackTrace();
    }
    Log.i("IPOSPRINTER","#### printerStatus"+printerStatus);
    return  printerStatus;
}

public ServiceConnection getServiceConnection(){
    return serviceConnection;
}

public void setMIPosPrinterService(IPosPrinterService value){
    this.mIPosPrinterService = value;
}

public IPosPrinterService getMIPosPrinterService(){
    return this.mIPosPrinterService;
}

public int testPrint(Bitmap bitmap) {
    this.printerInit();
    // Print images
    try {
        Log.i(TAG, "Start print Data");
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int newWidth = 384;
        Matrix matrix = new Matrix();
        if(width > newWidth) {
            float scaleWidth = (float) newWidth / (float) width;
            matrix.postScale(scaleWidth, 1.0F);
        }

        Bitmap bitmap1 = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
        this.mIPosPrinterService.printBitmap(1, 16, bitmap1, callback);  // 0, 17
        this.mIPosPrinterService.printBlankLines(10, 10, callback);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    int printerStatus = 0;
    try {
        printerStatus = this.mIPosPrinterService.getPrinterStatus();
    } catch (RemoteException e) {
        e.printStackTrace();
    }

    return printerStatus;
}

public void printerInit(){
    try{
        mIPosPrinterService.printerInit(callback);
    }catch (RemoteException e){
        e.printStackTrace();
    }
}

}

`

In this case, you are still trying to connect to the printer using the printer service provided. This would still work if you managed but will not be as fast as you connecting through the Bluetooth service. What I was asking you to do is to treat the printer like any other Bluetooth device that your POS Device is able to see. I would google something like How to discover and connect to a Bluetooth printer in java e.g https://www.androidcode.ninja/android-bluetooth-tutorial/.

All that you need is a printer address to send you text to for printing or you could also use ESC Commands to format your text and send it as a string to the printer.

@Hackbard
Copy link

Hackbard commented Sep 2, 2021

Thanks for the Tutorial i've testet it and it does the job ;)
Did you know, how i can get the Status of the Printer? My Printer is able to tell me if the print goes well or if paper is missing and things like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants