tencent cloud

Feedback

Last updated: 2024-11-21 17:34:28

    Process special URLs in web-view component

    If the webpage displayed in the web-view component contains special URLs, such as those starting with a custom scheme like tcmpp://host/path, the host app can intercept and customize the redirections of the URLs.
    To intercept URL navigation, create a class that implements the IWebViewLinkProxy API and add the ProxyService annotation:
    @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;
    }
    }
    In the implementation, the mini program context and the loaded URL are provided. If the developer handles the URL redirections and returns true, the web-view component will no longer process the URL. If false is returned, the web-view component will process the URL according to normal logic.
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support