如何使用 RSS Feed URL 构建 Intent 以打开 Podcast 应用程序?

Posted

技术标签:

【中文标题】如何使用 RSS Feed URL 构建 Intent 以打开 Podcast 应用程序?【英文标题】:How do I structure an Intent to open a Podcast App using an RSS Feed URL? 【发布时间】:2021-11-23 10:06:32 【问题描述】:

我有一个应用程序,其中包含用户生成的动态播客/RSS 提要 URL。例如,让我们使用这个 url:

http://leccap.engin.umich.edu/leccap/feed/podcast/sample-rec-7d9gq34m/4

由于这些 URL 是由内容创建者动态生成的,我需要获取 API 传递给我的 URL,并创建一个打开播客应用程序的意图。虽然我不认可其中任何一个,但为了提供上下文,以下是一些不熟悉的人的播客应用示例:

Google Podcasts Pocket Casts Podcast Player

由于我发送的意图可以由任何/所有这些应用程序打开,因此我不需要支持单个意图,只需找出正确的意图构建器逻辑,以便用户可以选择他们要使用的意图想用。

我有这个基本代码设置:

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        //Setting data / categories here

        this.startActivity(intent);

我已经尝试了意图类别和数据的以下变体:

        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        intent.setDataAndType(Uri.parse(podcastUrl), "*/*");
        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        intent.setDataAndType(Uri.parse(podcastUrl), "application/xml");
        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        intent.setData(Uri.parse(podcastUrl));
        intent.setData(Uri.parse(podcastUrl));
        intent.setData(Uri.parse(podcastUrl));
        intent = Intent.createChooser(intent, "Choose a Selection");

这些都无法通过深度链接实际重定向到本机播客播放器应用程序。我还尝试了 category 选项的多种变体,但似乎都没有改善。

根据Is there a standard way to subscribe to a feed using a podcast app?,我也尝试将http: / https: 字符串替换为feeditpc,IE

feed://leccap.engin.umich.edu/leccap/feed/podcast/sample-rec-7d9gq34m/4

还是什么都没有。

如何构建此 Intent,以便它向用户显示打开 Podcast 应用以处理所述提要 URL 的选项?

【问题讨论】:

所以,如果我正确理解了您的问题……您所说的是,一旦我点击了leccap.engin.umich.edu/leccap/feed/podcast/sample-rec-7d9gq34m/4 应用程序,我应该会转到这些列出的应用程序中的任何一个,对吗? 正确,使用该示例链接作为 url,我希望向用户显示他们可以选择打开 URL 的选项列表。根据我的研究,我似乎可以选择某些深度链接模式,例如 Google Podcast 应用程序或 Spotify,但我找不到任何可以播放播客的应用程序的方法。 您是否遇到过任何其他具有此功能的应用程序,即点击您提供的相同链接? @AgentP 顺便提了几个杂项,但我只见过在我的设备上打开 Google 播客;此外,如果您没有安装 Google 播客,它不会重定向到我正在测试的特定应用程序。 【参考方案1】:

事实证明,可以通过多种不同的方式设置播客,因此每个意图过滤器仅适用于其中的一些。需要使用许多不同的过滤器来获得对大多数订阅链接的预期效果。

以下是我发现的一些有效的过滤器:

<intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="itpc" />
                <data android:scheme="pcast" />
                <data android:scheme="feed" />
                <data android:scheme="rss" />
            </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:scheme="http" android:host="*"
                    android:pathPattern=".*xml" />
                <data android:scheme="http" android:host="*"
                    android:pathPattern=".*rss" />
                <data android:scheme="http" android:host="*"
                    android:pathPattern=".*feed.*" />
                <data android:scheme="http" android:host="*"
                    android:pathPattern=".*podcast.*" />
                <data android:scheme="http" android:host="*"
                    android:pathPattern=".*Podcast.*" />
                <data android:scheme="http" android:host="*"
                    android:pathPattern=".*rss.*" />
                <data android:scheme="http" android:host="*"
                    android:pathPattern=".*RSS.*" />
            </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:mimeType="text/xml" android:scheme="http" />
                <data android:mimeType="application/rss+xml" android:scheme="http" />
                <data android:mimeType="application/atom+xml" android:scheme="http" />
            </intent-filter>

【讨论】:

嗨,Nadeem,回答问题,但我相信您的回答解释了我的应用程序如何接收用于播客的意图,而我正在询问如何在我的应用程序中构建意图以链接到播客播放器应用程序。 我明白了。谢谢。我还浏览了https://***.com/questions/6200824/how-to-create-a-dynamic-intent-in-android/6201029。我的问题是否正确?

以上是关于如何使用 RSS Feed URL 构建 Intent 以打开 Podcast 应用程序?的主要内容,如果未能解决你的问题,请参考以下文章

有两个用于 WordPress 的 RSS Feed URL

Wordpress中的类别的Rss feed

如何在 iOS 上使用 Swift 将 1 个以上的 RSS Feed 解析并合并为一个 Feed

从RSS导入时如何避免重复结果

Wordpress Feed链接zu Feedburner leiten

如何实现RSS订阅