服务意图必须明确:Intent
Service Intent must be explicit: Intent
我正在尝试创建一个 RemoteService,我已经遵循了这个指南:
http://www.techotopia.com/index.php/Android_Remote_Bound_Services_%E2%80%93_A_Worked_Example
这是我在清单中的服务声明:
<service android:name=".RemoteService"
android:process=":InnolertRemoteProcess"
android:exported="true">
<intent-filter>
<action android:name="myService.RemoteService"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</service>
这就是我从我的客户端应用程序绑定到服务的方式:
Intent intent = new Intent("myService.RemoteService");
bindService(intent, myConnection, Context.BIND_AUTO_CREATE);
我得到这个异常:
java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=myService.RemoteService }
我用过这个。
public 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;
}
对我来说,下一行对我有帮助:
intent.setPackage("myServicePackageName");
例如:
Intent intent = new Intent("com.something.REQUEST_SOMETHING");
intent.setPackage("com.something");
ctx.startService(intent);
试试这个:
Intent i = new Intent();
i.setAction("myService.RemoteService");
i.setPackage("com.your_service_package.name");
boolean ret = bindService(i, connection, Context.BIND_AUTO_CREATE);
Log.d(TAG, "initService() bound with " + ret);
我正在尝试创建一个 RemoteService,我已经遵循了这个指南: http://www.techotopia.com/index.php/Android_Remote_Bound_Services_%E2%80%93_A_Worked_Example
这是我在清单中的服务声明:
<service android:name=".RemoteService"
android:process=":InnolertRemoteProcess"
android:exported="true">
<intent-filter>
<action android:name="myService.RemoteService"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</service>
这就是我从我的客户端应用程序绑定到服务的方式:
Intent intent = new Intent("myService.RemoteService");
bindService(intent, myConnection, Context.BIND_AUTO_CREATE);
我得到这个异常:
java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=myService.RemoteService }
我用过这个。
public 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;
}
对我来说,下一行对我有帮助: intent.setPackage("myServicePackageName");
例如:
Intent intent = new Intent("com.something.REQUEST_SOMETHING");
intent.setPackage("com.something");
ctx.startService(intent);
试试这个:
Intent i = new Intent();
i.setAction("myService.RemoteService");
i.setPackage("com.your_service_package.name");
boolean ret = bindService(i, connection, Context.BIND_AUTO_CREATE);
Log.d(TAG, "initService() bound with " + ret);