android L java.lang.IllegalArgumentException: Service Intent must be explicit隐式意图找不到错误解决
2014-12-10 16:02
716 查看
创建一个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 intent
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolveInfo = pm.queryIntentServices(implicitIntent, 0);
// Make sure only one match was found
if (resolveInfo == null || resolveInfo.size() != 1) {
return null;
}
// Get component info and create ComponentName
ResolveInfo 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 reuse
Intent explicitIntent = new Intent(implicitIntent);
// Set the component to be explicit
explicitIntent.setComponent(component);
return explicitIntent;
}
然后就可以跨进程调用了
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 intent
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolveInfo = pm.queryIntentServices(implicitIntent, 0);
// Make sure only one match was found
if (resolveInfo == null || resolveInfo.size() != 1) {
return null;
}
// Get component info and create ComponentName
ResolveInfo 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 reuse
Intent explicitIntent = new Intent(implicitIntent);
// Set the component to be explicit
explicitIntent.setComponent(component);
return explicitIntent;
}
然后就可以跨进程调用了
相关文章推荐
- Android报错:Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent
- java.lang.IllegalArgumentException: Service Intent must be explicit 异常解决
- 解决Android5.0及以上启动Service时,java.lang.IllegalArgumentException: Service Intent must be explicit
- java.lang.IllegalArgumentException: Service Intent must be explicit解决方法
- java.lang.IllegalArgumentException: Service Intent must be explicit解决方法
- java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.ba.cal
- java.lang.IllegalArgumentException: Service Intent must be explicit
- java.lang.IllegalArgumentException: Service Intent must be explicit: Intent {
- java.lang.IllegalArgumentException:Service Intent must be explicit:Intent{act=org.opencv.engine.BIND
- java.lang.IllegalArgumentException: Service Intent must be explicit异常说明
- java.lang.IllegalArgumentException: Service Intent must be explicit
- java.lang.illegalArgumentException:Service intent must be explicit
- java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=xxx}
- 20_ java.lang.IllegalArgumentException: Service Intent must be explicit异常说明
- Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit:
- android5.0之后必须显示调用,否则报java.lang.IllegalArgumentException: Service Intent must be explicit
- java.lang.IllegalArgumentException: Service Intent must be explicit
- java.lang.IllegalArgumentException: Service Intent must be explicit: Intent
- Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit:
- 5.0上java.lang.IllegalArgumentException: Service Intent must be explicit异常