正常启动
Intent intent = new Intent();
intent.setComponent(new ComponentName(PACKAGE_NAME,CLASS_NAME));
bindService(intent, this.mConnection, BIND_AUTO_CREATE);
不知道对方的包名类名,但是知道对面过滤器的action
Intent mIntent = new Intent();
mIntent.setAction("action"); 发送action(根据对面服务的action发送action)
_context.bindService(getExplicitIntent(getActivity(),mIntent), new ServiceBtControl(), Context.BIND_AUTO_CREATE); 绑定服务
private static Intent getExplicitIntent(Context context,Intent implicitIntent) {
PackageManager pm = context.getPackageManager();
ResolveInfo resolveInfo = pm.resolveService(implicitIntent, 0);
LogTool.d(cTag, "packageName :"+resolveInfo.serviceInfo.packageName
+",className:"+resolveInfo.serviceInfo.name);
ComponentName component = new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
// 创建一个新的意图。使用旧的一个额外的和这样的重用
Intent explicitIntent = new Intent(implicitIntent);
// 将组件设置为显式
explicitIntent.setComponent(component);
return explicitIntent;
}