我有两个独立的应用程序,理想情况下我想使用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 Activity:
当前为:
@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)
你可以这样通过intent调用IntentFilter:
@Override
protected void onResume() {
super.onResume();
Intent intent = new Intent("IntentFilterName");
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}