0

我创建了一个名为 connection 的 ServiceConnection 对象。

但是,永远不会调用 onServiceConnected 方法。

关于如何让它工作的任何想法?谢谢

这是我的代码:

public static boolean print(String message){
    if(printerInitialized != true){
        Log.e(TAG,"Unitialized printer. Can't print");
        return false;
    }


    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra("MAC", printerUuid);
    sendIntent.putExtra("DATA", message);
    sendIntent.setComponent(new ComponentName("com.blueslib.android.app","com.blueslib.android.app.PrintService"));

    context.getApplicationContext().bindService(sendIntent,connection, Context.BIND_AUTO_CREATE);

    return true;
}

public static ServiceConnection connection = new ServiceConnection() {

    @Override
    public void onServiceDisconnected(ComponentName name) {
        Log.e("System.out", "Service Disconnected");
    }

    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        Log.e("System.out", "Service connected");
    }
};
4

0 回答 0