AID连接服务端service,startService和bindService都没有连接成功
public class MainActivity extends AppCompatActivity {
final static String TAG = "MainActivity";
MyserviceInterface mi;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
Log.d(TAG,"serviceconnection__________");
mi = MyserviceInterface.Stub.asInterface(iBinder);
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
}
};
@Override
protected void onDestroy() {
super.onDestroy();
unbindService(serviceConnection);
}
public void unbind(View view) {
unbindService(serviceConnection);
}
public void bind(View view) {
intent = new Intent();
intent.setAction("android.intent.action.RESPOND_VIA_MESSAGE");
intent.setPackage("com.example.serviceaidl");
bindService(intent,serviceConnection,BIND_AUTO_CREATE);
}
public void star(View view) {
intent = new Intent();
intent.setAction("android.intent.action.RESPOND_VIA_MESSAGE");
intent.setPackage("com.example.serviceaidl");
startService(intent);
}
public void stop(View view) {
intent = new Intent();
intent.setAction("android.intent.action.RESPOND_VIA_MESSAGE");
intent.setPackage("com.example.serviceaidl");
stopService(intent);
}
}
包名和action<action android:name="android.intent.action.RESPOND_VIA_MESSAGE"/>
package="com.example.serviceaidl">
包名和action都一样,但是还是没有连接成功
log提示啥?package="com.example.serviceaidl"
这个是你在清单文件里注册的内容吧,不用添加这个。使用action就好。
如果是5.1以上的系统,你在绑的时候,intent添加上对方的包名。