Android 安卓:bindService赢得';t连接到远程(AIDL)服务,以及i';我不知道为什么

Android 安卓:bindService赢得';t连接到远程(AIDL)服务,以及i';我不知道为什么,android,service,aidl,Android,Service,Aidl,我正在尝试在Android 2.2.1上开发一个基本的AIDL服务。似乎所有的构建和安装都正常,但bindService()就是不能绑定。未调用我的ServiceConnection类。我真的不知道为什么不能,所以任何帮助都将不胜感激。以下是我的客户活动: public class go extends Activity { protected static final String TAG = "HOSPlayerClient"; private IHOSPlayerServi

我正在尝试在Android 2.2.1上开发一个基本的AIDL服务。似乎所有的构建和安装都正常,但bindService()就是不能绑定。未调用我的ServiceConnection类。我真的不知道为什么不能,所以任何帮助都将不胜感激。以下是我的客户活动:

public class go extends Activity {
    protected static final String TAG = "HOSPlayerClient";
    private IHOSPlayerService hosPlayerService = null;

    private ServiceConnection serviceConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName name, IBinder service) {
            Log.v(TAG, "onServiceConnection");
            hosPlayerService = IHOSPlayerService.Stub.asInterface(service);
            callService();
        }

        public void onServiceDisconnected(ComponentName name) {
            Log.v(TAG, "onServiceDisconnected");
        }
    };

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.v(TAG, IHOSPlayerService.class.getName());
        boolean bound = bindService(
                new Intent(IHOSPlayerService.class.getName()),
                serviceConnection, Context.BIND_AUTO_CREATE);

        Log.v(TAG, bound ? "service bound" : "service bind failed");
    }

    private void callService() {
        try {
            hosPlayerService.go();
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
。。。以下是我认为与AIDL服务相关的部分:

public class HOSPlayerService extends Service
{
 private static final String TAG = "HOSPlayerService";

 public class HOSPlayerServiceImpl extends IHOSPlayerService.Stub
 {
  public void go() throws RemoteException
  {
   Log.v(TAG, "go called");
  }
 }

 @Override
 public IBinder onBind(Intent intent) 
 {
  // TODO Auto-generated method stub
  return new HOSPlayerServiceImpl();
 }
}
。。。以及AIDL文件:

package com.HOS.ahos.HOSPlayerService;

interface IHOSPlayerService
{
 void go();
}

尝试将以下代码放入服务文件中-

@Override
public IBinder onBind(Intent arg0) {
    //arg0.getExtras();
    return binder;
}

服务应该返回binder,然后只调用MyServiceConnection类。

使用Eclipse中的
adb logcat
、DDMS或DDMS透视图来检查logcat,并查看在调用
bindService()
时是否有任何警告。最有可能的警告是,IMHO,Android找不到该服务。这可能是因为您的清单中没有它,或者您的
与传递给
bindService()
意图不匹配。这两个应用程序中的包名和文件名相同吗?