为什么 Android 深层链接使我在 Whatsapp 上的链接在 Whatsapp 的应用程序内打开?

use*_*065 3 android deep-linking webview android-webview android-studio

我正在逐步按照本教程在 Android 上进行深度链接。部分代码如下,基本上它会在我的应用程序的webview中打开url。

Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
if (data != null) {
    String path = data.getPath();
    String query = data.getEncodedQuery();
    String hash = data.getEncodedFragment();

    String fullPath = path;
    if(query !=  null){
        fullPath = path + "?" + query;
        if(hash != null){
            fullPath = path + "#" + hash;
        }
    }

    String openUrl = "https://" + Config.domain + fullPath;

    ....
    // and open in webview

}
Run Code Online (Sandbox Code Playgroud)

它几乎完美地工作。Chrome 浏览器上的链接可以在我的应用程序中打开。但是,当单击 Whatsapp 等消息传递应用程序上的链接时,该链接会在 Whatsapp 本身上打开,并替换 Whatsapp 上的原始内容!而且我无法返回 Whatsapp 的正常消息屏幕,除非我退出该应用程序并再次打开它!

为什么会出现这样的情况?我需要做什么来解决它?谢谢!

小智 5

我遇到了完全相同的问题,这是因为我将“launchMode”设置为 singleTop。我将其更改为 singleTask 并且完美运行。