【问题标题】:Handling external links in android webview处理android webview中的外部链接
【发布时间】:2019-12-28 15:39:15
【问题描述】:

我想在点击特定链接时打开我的应用并加载 URL。

这是我处理外部链接的清单。

<intent-filter android:autoVerify="true">
    <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="www.android.com" />
    <data android:scheme="https" android:host="www.android.com" />
</intent-filter>

处理传入链接的代码

    intentData = getIntent().getData();
    if(intentData !=null){
        loadUrl = intentData.toString();
    }else {
        loadUrl = "https://www.android.com";
    }
    webView.loadUrl(loadUrl);

现在,当我从诸如whatsapp 之类的外部应用程序中单击https://www.android.com 时,它已加载到webview 中,但webview 已附加到whatsapp。检查下面的屏幕截图。


如果有人可以在我从谷歌浏览器(在我的手机中)打开 URL(https://www.android.com) 时给我任何提示或指导我如何打开我的应用程序,那将是一个很大的帮助

【问题讨论】:

    标签: android webview external-links


    【解决方案1】:

    关于你问题的第二部分:

    如果有人可以给我任何提示或指导我如何打开我的应用程序 当我从谷歌浏览器打开 URL(https://www.android.com)时(在我的 电话)将是一个很大的帮助

    看看this的回答:

    “基本上,Chrome 团队认为,如果用户实际上在地址栏中输入了某些内容,则永远不会发生重定向。正如您所发现的,这与所有其他浏览器中的行为背道而驰。”

    【讨论】:

    • 谢谢您的信息。 Branch.io 是个有用的东西。
    【解决方案2】:

    在您的 Activity 的 Manifest 文件中使用这一行来处理该意图以避免此类问题。

    android:launchMode="singleTask"
    

    【讨论】:

      【解决方案3】:

      你可以在这里找到详细的实现,https://developer.android.com/guide/webapps/webview.html

      您必须重写方法并处理点击。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-11
        • 2016-11-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-05
        • 2012-12-26
        相关资源
        最近更新 更多