Android examples for java.net:URL
checks and ensure http/https protocol in URL
import android.util.Log; import java.net.URLDecoder; import java.util.Collection; import java.util.regex.Pattern; public class Main{ /**//from w w w . j a v a2 s .c om * This method checks and ensure http/https protocol in URL * * @param url * @return formattedUrl */ public static String getFormattedURL(String url) { if (url.indexOf("http://") == 0 || url.indexOf("https://") == 0) { return url; } else if (url.indexOf("://") == 0) { return "http" + url; } else if (url.indexOf("//") == 0) { return "http:" + url; } else { return "http://" + url; } } }