Reputation: 85
I have an app to share YouTube videos. Edittext text must should be a link in this purpose. But the problem is that I don't know how to detect if it is a link or simple text. Let say I have an edittext with id edittext1. On button1 click i shall check if edittext consists of a link or not. Thanks in advance.
Upvotes: 3
Views: 1134
Reputation: 534
You can create your own implementation I think there are two methods you can use
x.startWith(str)
Method. Is your string is starting with http or https then you can treat is as link else treat it as text.x.contains(str)
NOTE:
x = edittext1.getText().toString();
Upvotes: 2
Reputation: 4070
You can use URLUtil.isValidUrl(url)
to check if a string is a valid URL.
P.S - Do note that there are many ways that a URL can be well-formed but not retrievable. It's always best to ensure that you're catching any potential exceptions that might be thrown even after you check if the URL is valid.
Upvotes: 4