【问题标题】:BroadcastReceiver doesn't receive Intents from outer linksBroadcastReceiver 不接收来自外部链接的 Intent
【发布时间】:2015-06-23 16:35:28
【问题描述】:

我有一个具有如下意图过滤器的 BroadcastReceiver:

    <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 或其他地方的共享链接时,该链接来自我们的网站,它无法识别已安装的应用程序。

【问题讨论】:

  • 显示 whole 清单,而不仅仅是 &lt;intent-filter&gt;
  • 顾名思义,广播接收器接收广播。 URL 不是广播。

标签: android broadcastreceiver intentfilter


【解决方案1】:

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

<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>

【讨论】:

  • 我真的很想用接收器制作它,但您的解决方案正在运行。
  • 现在的问题是,它不会像 facebook 应用程序那样处理来自 chrome 的链接。
  • 是指点击 chrome 中的链接还是将链接输入浏览器?
  • 当我点击链接时
  • 嗯...这很有趣。通常,他们链接的应用程序被点击并不重要
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多