我有一个问题。我需要中断链接,但这些链接不是静态的,而是用户在运行时创建的列表。因此,我需要在运行时创建我的intentfilter对象。当我在清单文件中使用代码时它可以工作。但是,在Java类中使用它对我来说不起作用。以下是代码:
这段代码不起作用。
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_VIEW);
filter.addCategory(Intent.CATEGORY_DEFAULT);
filter.addCategory(Intent.CATEGORY_BROWSABLE);
filter.addDataAuthority("www.facebook.com", null);
filter.addDataScheme("http");
RecieveBroadcaster receiver = new RecieveBroadcaster();
registerReceiver(receiver, filter);
但是如果静态设置,它会在清单文件中起作用。
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http" android:host="twitter.com"/>
<data android:scheme="http" android:host="facebook.com"/>
</intent-filter>