마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

html 페이지가 있는지 여부 체크는 어떻게 하나요?

0 추천
가령 webview를 실행하기 전 로딩할 html페이지가 있는지 여부를 간단히 체크할 수 있는 방법이 있나요..?
익명사용자 님이 2015년 2월 22일 질문

1개의 답변

0 추천
 
채택된 답변
> url 검사
 
public static boolean checkURL(CharSequence input) {
    if (TextUtils.isEmpty(input)) {
        return false;
    }
    Pattern URL_PATTERN = Patterns.WEB_URL;
    boolean isURL = URL_PATTERN.matcher(input).matches();
    if (!isURL) {
        String urlString = input + "";
        if (URLUtil.isNetworkUrl(urlString)) {
            try {
                new URL(urlString);
                isURL = true;
            } catch (Exception e) {
            }
        }
    }
    return isURL;
}
 
 
> get html
 
HttpClient httpclient = new DefaultHttpClient(); // Create HTTP Client
HttpGet httpget = new HttpGet("http://yoururl.com"); // Set the action you want to do
HttpResponse response = httpclient.execute(httpget); // Executeit
HttpEntity entity = response.getEntity(); 
InputStream is = entity.getContent(); // Create an InputStream with the response
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) // Read line by line
    sb.append(line + "\n");
 
String resString = sb.toString(); // Result is here
 
is.close(); // Close the stream
 
 
 
---------------------------------------------
 
doridori2013@nate.com (nateon)
 
 
 
 
 
익명사용자 님이 2015년 2월 22일 답변
...