创建一个serviceconnection实例private ServiceConnection serviceConnection = new ServiceConnection() {@Override public void onServiceDisconnected(ComponentName name) { // TODO Auto-generated method stub } @Override public void onServiceConnected(ComponentName name, IBinder service) { // TODO Auto-generated method stub } };绑定服务bindService( createExplicitFromImplicitIntent( getApplicationContext(), new Intent("你要绑定的aidl服务")), serviceConnection, Context.BIND_AUTO_CREATE);//获取要绑定的服务的intentpublic static Intent createExplicitFromImplicitIntent( Context context, Intent implicitIntent) {// Retrieve all services that can match the given intentPackageManager pm = context .getPackageManager();List<ResolveInfo> resolveInfo = pm .queryIntentServices(implicitIntent, 0);// Make sure only one match was foundif (resolveInfo == null || resolveInfo .size() != 1) {return null;}// Get component info and create ComponentNameResolveInfo serviceInfo = resolveInfo .get( 0);String packageName = serviceInfo .serviceInfo .packageName;String className = serviceInfo .serviceInfo .name;ComponentName component = new ComponentName(packageName, className);// Create a new intent. Use the old one for extras and such reuseIntent explicitIntent = new Intent(implicitIntent);// Set the component to be explicitexplicitIntent .setComponent(component);return explicitIntent;}然后就可以跨进程调用了
android L java.lang.IllegalArgumentException: Service Intent must be explicit隐式意图找不到错误解决
最新推荐文章于 2022-09-23 08:38:11 发布