gpt4 book ai didi

android - BroadcastReceiver 不接收来自外部链接的 Intents

转载 作者:搜寻专家 更新时间:2023-11-01 08:43:01 26 4
gpt4 key购买 nike

我有一个 BroadcastReceiver,它有这样的 Intent 过滤器:

    <receiver
android:name="com.mytestpackage.ExternalLinksBroadcastReceiver"
android:exported="true"
android:enabled="true">
<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:host="test.me"
android:path="/static/"
android:scheme="http"/>
</intent-filter>
</receiver>

我想从广播接收器打开这样的链接。

http://test.me/static/someone-1111"

接收器的 OnReceive 我从 Intent 中提取用户 ID 并尝试在应用程序中显示相应的配置文件。

这行不通。现在,当我使用上面的方案在 Facebook 或其他地方单击共享链接时,该链接来 self 们的网站,它无法识别已安装的应用程序。

最佳答案

如果您想通过自定义 url 方案打开您的应用程序,您需要为 Activity 声明方案,而不是广播接收器。尝试这样的事情:

<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-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:host="test.me"
android:path="/static/"
android:scheme="http"/>
</intent-filter>
</activity>

关于android - BroadcastReceiver 不接收来自外部链接的 Intents,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31008503/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com