服务端:Service 所在 AndroidManifest.xml 中的配置如下,enable="true"设置可用,exported="true"对外暴露, 这样其他的Activity才能被其他 App 访问,否则就只限于应用内。
客户端:需要开启远程服务
Intent service = new Intent();
service.setAction("com.sl.aidl"); //service 的 action 值
service.setPackage("com.sl.binderservice"); //远程服务所在包名//绑定服务
bindService(service, mConnection, Context.BIND_AUTO_CREATE);//启动服务startService(service);
二、显示开启
服务端:AndroidManifest.xml
客户端:
public static final String NAME_REMOTE_SERVICE = "com.sl.binderservice.BookManagerService" ; public static final String PACKAGE_REMOTE_SERVICE = "com.sl.binderservice" ; //启动服务 Intent startIntent = new Intent (); ComponentName componentName = new ComponentName(PACKAGE_REMOTE_SERVICE ,NAME_REMOTE_SERVICE); startIntent .setComponent (componentName ); startService( startIntent) ; //绑定服务 Intent startIntent = new Intent (); ComponentName componentName = new ComponentName(PACKAGE_REMOTE_SERVICE ,NAME_REMOTE_SERVICE); startIntent .setComponent (componentName ); bindService( startIntent, mConnection, Context.BIND_AUTO_CREATE) ;



