如何检查 URL 在 Android 中是否有效 [英] How to check if URL is valid in Android

查看:55
本文介绍了如何检查 URL 在 Android 中是否有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么好方法可以避免主机未解析"错误导致应用程序崩溃?某种尝试连接到主机(如 URL)并查看它是否有效的方法?

Is there a good way to avoid the "host is not resolved" error that crashes an app? Some sort of a way to try connecting to a host ( like a URL ) and see if it's even valid?

推荐答案

使用 URLUtil 验证 URL,如下所示.

Use URLUtil to validate the URL as below.

 URLUtil.isValidUrl(url)

如果 URL 有效则返回真如果 URL 无效则返回假.

这篇关于如何检查 URL 在 Android 中是否有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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