如何启用深层链接在网页视图上的Andr​​oid应用? [英] How to enable deep-linking in WebView on Android app?

查看:236
本文介绍了如何启用深层链接在网页视图上的Andr​​oid应用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现Android应用深层链接。

I'm trying to implement deep linking in android app.

当我点击自定义网址(XXXX?://转贴ID = 12)的深层链接。在Android浏览器如Chrome,我的应用程序打开了,而且运作非常好

When I click the deep linking of custom url (xxxx://repost?id=12) on Android browser like Chrome, my app opens up and works very well.

问题是,在应用程序中,有一个web视图控件,我想深联工作的也有。

Problem is, in the app, there's a webView widget, and I want to the deep-linking work there too.

目前,它显示无法连接到服务器错误。

先谢谢了。

推荐答案

这是与Android Web视图的问题,因为这种对待一切,网址,但其他浏览器,如移动拦截铬方案和操作系统将完成剩下的开相应的应用程​​序。
要实现这一点,你需要修改你的Web视图shouldOverrideUrlLoading功能如下:

This is the problem with android web view as this treats everything as URL but other browser like chrome on mobile intercepts the scheme and OS will do the rest to open the corresponding app. To implement this you need to modify your web view shouldOverrideUrlLoading functions as follows:

 @Override
 public boolean shouldOverrideUrlLoading(WebView view, String url) {
        LogUtils.info(TAG, "shouldOverrideUrlLoading: " + url);
        Intent intent;

        if (url.contains(AppConstants.DEEP_LINK_PREFIX)) {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            startActivity(intent);

            return true;
        } 
 }

在上面code用URL方案如更换AppConstants.DEEP_LINK_ preFIX。

In above code replace AppConstants.DEEP_LINK_PREFIX with your url scheme eg.

Android的应用程序://你的包

android-app://your package

希望这有助于!

这篇关于如何启用深层链接在网页视图上的Andr​​oid应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆