运行时创建的IntentFilter无法正常工作

3

我有一个问题。我需要中断链接,但这些链接不是静态的,而是用户在运行时创建的列表。因此,我需要在运行时创建我的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>     

这个链接可能会有帮助:http://stackoverflow.com/questions/2230280/capturing-home-intent-programmatically - Triode
可能是我的应用程序的重复问题 中断链接到我的应用程序 - user
1个回答

0
在这种情况下,可能只是因为您的权限不匹配。在清单版本中,您有android:host =“facebook.com”,而在编程版本中,您有addDataAuthority(“www.facebook.com”,null)。
DataAuthority必须完全匹配。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接