如何让OnServiceConnected运行?

时间:2013-08-15 20:45:02

标签: android android-service

我创建了一个名为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");
    }
};

0 个答案:

没有答案