直到一个月前,我才成功地从我的另一个应用程序使用intent-filter
开始服务.
应用A:
<service
android:name="com.example.app.MyService"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="com.test.START" />
</intent-filter>
</service>
应用程序B:
public static Intent createExplicitIntent(Context context, Intent intent) {
List<ResolveInfo> queryIntentServices = context.getPackageManager().queryIntentServices(intent, 0);
System.out.println(queryIntentServices.size());
if (queryIntentServices.size() != 1) {
return null;
}
ResolveInfo resolveInfo = queryIntentServices.get(0);
ComponentName componentName = new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
Intent intent2 = new Intent(intent);
intent2.setComponent(componentName);
return intent2;
}
然后,最后是:
Intent intent = new Intent("com.test.START");
createExplicitIntent(context, intent);
但由于某种原因,它停止了工作.我不确定我做了什么改变, destruct 了这种方法.