java코딩.
package com.aa;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Properties;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class JrecoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(onClick);
}
private Button.OnClickListener onClick = new Button.OnClickListener() {
public void onClick(View v) {
String html;
html ="http://www.plimit.com/test.html";
EditText result = (EditText) findViewById(R.id.editText1);
result.setText(getStringFromURL("html);
}
};
public static String getStringFromURL("String strURL)
{
StringBuffer sbResult = new StringBuffer();
try
{
// Proxy Setting
String strProxyAddress = "http://www.plimit.com/test.html";
String strProxyPort = "8080";
Properties properties = System.getProperties();
properties.setProperty("http.proxyHost", strProxyAddress);
properties.setProperty("http.proxyPort", strProxyPort);
// Http Connection
URL url = new URL("strURL);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
if (connection != null)
{
connection.setConnectTimeout(5000); // Set Timeout
connection.setUseCaches(false);
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK)
{
BufferedReader br = new BufferedReader(
new InputStreamReader(connection.getInputStream(),
"EUC-KR"));
String strLine = null;
while ((strLine = br.readLine()) != null)
{
sbResult.append(strLine + "\n");
}
br.close();
}
connection.disconnect();
}
}
catch (Exception e)
{
e.printStackTrace();
}
return sbResult.toString();
}
}
manifest .xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aa"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".JrecoActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
</LinearLayout>
현재 예제를 보고 만든것인데... 버튼을 클릭하면 빈칸으로 나오네여 ㅠㅠ
해당테스트 사이트에는
이렇게 텍스트가 있는데
흑미밥만 보여지게 하고싶습니다..
어디가 잘못코딩되었는지 찾을수 없어서 도움을 요청드리겠습니다. ㅠㅠ
라이브러리는 jericho-android.3.1.jar
를 사용하였습니다.
안드로이드 인터넷 strict mode 검색해보세요