我学习Java已经有一段时间了,用来开发Android应用程序。此时,我希望我的网站重定向到我的应用程序。这应该是可能的使用意图-过滤器我的网站-url。我以stackoverflow.com主页为例。
我在Android中的MainActivity部分中使用了以下代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nl.example.webitent" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<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>
<data android:scheme="http" android:host="stackoverflow.com"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
</application>
</manifest>到目前为止没什么有趣的。这实际上是一个空白的活动,在一个新的项目添加意图-过滤器。我有target-sdk 21和最小sdk 16。然而,无论我尝试什么,它都不会在我去stackoverflow.com时触发,无论是直接还是通过href。
到底发生了什么,或者我做错了什么?
发布于 2015-08-03 21:22:37
当您在浏览器中访问stackoverflow.com时,不会触发意图。只有当应用程序明确地这样做时,才会触发意图。如果应用程序(您的浏览器)不应该打开您的url方案,情况就是这样。例如,mailto将在您的邮件应用程序中打开。因此,您必须创建自己的URL方案,如下所示
<intent-filter>
<data android:scheme="myweb" android:host="stackoverflow.com"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>然后一个指向myweb://stackoverflow.com的链接会打开你的应用程序。
https://stackoverflow.com/questions/31796815
复制相似问题