您的位置:首页 > 移动开发 > Android开发

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;
}
然后就可以跨进程调用了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐