我有两个独立的应用程序,理想情况下我想使用IntentFilter绑定到第二个应用程序上的服务。这可能吗?
在app 1 Manifest:
<service
android:name=".ServiceName"
android:exported="true"
android:icon="@drawable/ic_launcher"
android:label="Bound Service" >
<intent-filter>
<action android:name="IntentFilterName" />
</intent-filter>
</service>
在app 2活动中:
目前:
@Override
protected void onResume() {
super.onResume();
Intent i = new Intent();
i.setComponent(new ComponentName("com.test.application1", "com.test.application1.ServiceName"));
bindService(i, mConnection, Context.BIND_AUTO_CREATE);
}
是否可以像这样工作:
@Override
protected void onResume() {
super.onResume();
IntentFilter filter1 = new IntentFilter("IntentFilterName");
bindService(filter1, mConnection, Context.BIND_AUTO_CREATE);
}
我收到以下错误:
The method bindService(Intent, ServiceConnection, int) in the type ContextWrapper is not applicable for the arguments (IntentFilter, ServiceConnection, int)
答案 0 :(得分:1)
您可以通过意图调用IntentFilter:
@Override
protected void onResume() {
super.onResume();
Intent intent = new Intent("IntentFilterName");
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}