我已经为我的活动实现了深度链接。但是,单击链接时,会打开一个 Intent 选择器,询问是从应用程序还是从浏览器打开。如何直接从应用程序打开?
此外,如果未安装该应用程序,则不会将其带到Playstore。它会在浏览器中打开。
以下是我在清单中的代码:
<activity android:name=".activities.VideoNewsDetailActivity"
android:theme="@style/AppThemeActivity"
android:configChanges="orientation|screenSize"
>
<!-- Add this new section to your Activity -->
<intent-filter android:label="@string/videoNewsDetail">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Handle urls starting with "http://www.example.com/products" -->
<data android:scheme="http"
android:host="ddnews.apprikart.in"
android:pathPrefix="/videos" />
<!-- Handle local urls starting with "example://products" -->
<data android:scheme="ddnews.apprikart"
android:host="videos" />
</intent-filter>
</activity>
这就是意图过滤器的工作方式。如果超过 1 个应用可以处理您的意图,它将显示意图选择器。用户是否要在应用或浏览器中打开链接取决于用户。
您的服务器应该处理游戏商店重定向部分。例如,您的深度链接网址 http://www.example.com/page/1。现在,当应用程序未安装时,服务器可以检查是否从浏览器调用了该网址,然后它应该将浏览器重定向到Playstore的应用程序网址。
@Eric B.是对的。即使你希望只有你的应用程序可以打开该链接,那么你也需要在intent-filter
中使用自定义方案,例如:
android:scheme="ddnews"
并且需要建立这样的链接,ddnews://domain.com/dir/page.html