tencent cloud

文档反馈

最后更新时间:2024-08-13 17:10:36

    WebView 组件中特殊链接处理

    如果 WebView 组件展示的网页中存在特殊的 URL 链接,例如 tcmpp://host/path 这种以自定义 scheme 开头的链接,宿主可以接管这些链接的跳转操作,并自定义跳转行为。
    接管链接跳转应当创建类实现 IWebViewLinkProxy 接口,并添加 ProxyService 注解:
    @ProxyService(proxy = IWebViewLinkProxy.class) public class CustomWebViewLinkProxy implements IWebViewLinkProxy { /** * Handle custom url loading in web-view component. * Custom url is url with any custom scheme (scheme not network protocol such as http/https) * @param miniContext context of mini-program * @param url the url which is loading * @return return true if the url loading is handled, otherwise false the web-view will handle url loading */ @Override public boolean webViewCustomUrlLoading(IMiniAppContext miniContext, String url) { Uri uri = Uri.parse(url); if ("tcmpp".equals(uri.getScheme())) { Intent intent = new Intent(Intent.ACTION_VIEW, uri); miniContext.getAttachedActivity().startActivity(intent); return true; } return false; } }
    实现方法中提供了小程序上下文以及被加载的链接。如果开发者处理了链接跳转并返回 true,web-view 将不再处理该链接。如果返回 false,web-view 将按照正常逻辑处理该链接。
    联系我们

    联系我们,为您的业务提供专属服务。

    技术支持

    如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

    7x24 电话支持