java - Webview 是否有任何引用其域的外部链接?

标签 java android dns android-webview hyperlink

您是否知道,当您单击任何链接时,系统会询问您要使用哪个浏览器/应用程序打开它?从这个概念开始,是否可以在我的 WebView 中做到这一点?例如,当域名为 www.stackoverflow.com 时,它会询问我是否要使用我的 webview 打开该链接(仅为 stackoverflow 链接创建)?不知道我说清楚了没有。

最佳答案

<activity> 下写入以下标签在您的 AndroidManifest.xml 中。

当用户单击 StackOverflow 链接时,系统会将您的应用包含在列表中。

<intent-filter>
  <action android:name="android.intent.action.VIEW"></action>
  <category android:name="android.intent.category.DEFAULT"></category>
  <category android:name="android.intent.category.BROWSABLE"></category>
  <data android:host="www.stackoverflow.com" android:scheme="http"></data>
</intent-filter>

已更新

您可以使用getIntent()在你的Activity里面获取参数(URL)。在 onCreate 中添加以下行你的方法Activity .

    Intent intent = getIntent();
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        String url = intent.getData().toString();
        webView.loadUrl(url);
    }

关于java - Webview 是否有任何引用其域的外部链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18693939/

相关文章:

linux - Docker 不能托管多个网络服务器吗?

java - 将 XML 解析为 JSON

java - Android Javascript 接口(interface)失败

Kubernetes DNS 不再解析名称

android - 谷歌播放 : The form field "Compliance Status" to delete a previously declared Permission for a new APK is not shown

html - 在android中解码HTML实体

hadoop - 外部访问部署在 Kubernetes 中的 Hadoop HDFS

java - 在 FOR 循环中使用大量 IF 语句

java - 使用 SimpleDateFormat 的问题

java - InputstreamReader 只读取一行?