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 {
@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.
Was this page helpful?