我使用aidl文件构建一个简单的远程服务。服务和活动在两个不同的虚拟设备中。活动无法访问该服务。我认为该服务无法启动。 在DDMS视图中,我的服务不会出现,LogCat会启动错误:无法启动服务Intent {cmp = com.michelService.BIND pkg = com.michelService}:not found
感谢您的帮助!
我的AndroidManifest.xml:
*<?xml *version*="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.michelService"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="13" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<service android:name=".ServiceHello" android:exported="true" >
<intent-filter>
<action android:name="com.michelService.BIND"></action>
</intent-filter>
</service>
</application>
</manifest>*
我的活动:CallServiceActivity.java:
public class CallServiceActivity extends Activity {
/** Called when the activity is first created. */
IServiceHello service;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
TextView tv1 = new TextView(this);
Intent intent = new Intent();
intent.setAction("com.michelService.BIND");
intent.setPackage("com.michelService");
startService(intent);
ServiceConnection con = new ServiceConnection(){
@Override
public void onServiceConnected(ComponentName arg0, IBinder binder) {
service = IServiceHello.Stub.asInterface(binder);
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
service= null;
}
};
bindService(intent, con, Context.BIND_AUTO_CREATE);
try {
tv1.setText(service.sayHello("Michel"));
} catch (RemoteException e) {
// TODO Auto-generated catch block
tv1.setText("" + e);
}
layout.addView(tv1);
setContentView(layout);
}
}