【发布时间】:2016-05-18 00:21:01
【问题描述】:
我想在我的简单 Android 应用程序中实现这样的功能:当用户在网络浏览器中访问某个链接(比如说 www.example.org)时 - 如果安装了 Android 操作系统,它应该会打开我的 Android 应用程序。
我尝试使用这样的意图过滤器:
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<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="example.org"
android:pathPattern="/.*"
android:scheme="http" />
<data
android:host="www.example.org"
android:pathPattern="/.*"
android:scheme="http"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
但它在 google chrome 移动浏览器中根本不起作用。在 Firefox 中,当我访问该链接时,我会在搜索栏的右侧看到这样的 Android 图标:
当我按下该图标时 - 我的应用程序打开。但这仍然不是我想要实现的目标。
知道为什么我上面的代码不起作用吗?我尝试了许多我在互联网上找到的意图过滤器声明的变体,但似乎没有任何效果。我有安装了 Android 6 的 nexus 5 设备。
【问题讨论】:
标签: java android html android-intent web