안드로이드 개발 질문/답변
(글 수 45,052)
package com.androidhuman.example.parser;
import java.net.URL;
import net.htmlparser.jericho.Source;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class ParserActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String text1;
String text2;
String text3="같다 ";
String text4="다르다";
String yourUrl = "http://cafe.naver.com/kaujongsul/";
text1=getHtmltoText(yourUrl);
this.sleep(10000);
text2 = getHtmltoText(yourUrl);
if(text1.equals(text2)){
TextView tv2 = (TextView)findViewById(R.id.result1);
tv2.setText(text3);
}
else{
TextView tv = (TextView)findViewById(R.id.result2);
tv.setText(text4);
}
}
public String getHtmltoText(String sourceUrlString) {
Source source = null;
String content = null;
try {
//url에서 html 소스를 읽어온다.
source=new Source(new URL("sourceUrlString);
// 한글사용을 위해서는 윗 줄의 코드를 아래처럼 수정
// URL sUrl = new URL("sourceUrlString);
// InputStream is = sUrl.openStream();
// Source source= new Source(new InputStreamReader(is,"euc-kr"));
// "euc-kr" 부분은 charset에 맞춰 변경해준다. UTF-8, KSC5601 etc...
// 전체 소스 구문을 분석한다.
source.fullSequentialParse();
// HTML markup에서 text contents만 가져와서 스트링으로 변환한다.
content=source.getTextExtractor().toString();
} catch (Exception e) {
e.printStackTrace();
}
return content;
}
public void sleep(int time){
try {
Thread.sleep(time);
} catch (InterruptedException e) { }
}
}
이러한 작업을 지속적으로 해서 두 값을 비교 해서
두 값이 다르면 notification등을 이용해 알려줄려고 하는데
감이 안잡히네요..
여기까지 짜는데도 많은 고생을..ㅠ.ㅠ.
도와주세요 제발요.ㅠ.ㅠ.




꼭 sleep 안쓰시더라도 handler message delay 줘서 시간마다 getHtmltoText 시킨 이후에 이전에 받았던 값과 새로 받은 값을 비교하시면 되지 않나요?