-2
내가 textview1에서 텍스트를 읽을 필요가
에서 텍스트를 얻을 Android 기기, 수 없습니다하지만 텍스트는 항상텍스트 뷰
또는 "-shutdown"텍스트를 표시 "-shutdown"로하지만, 텍스트 뷰에 동일하지 않습니다 boolean totoString()에서 텍스트를 직접 읽을 수있는 다른 방법이 있습니까?
감사합니다.
내 활동 클래스 :
package com.example.androrem;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.NetworkOnMainThreadException;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class ReadSMS extends Activity {
private static final int duration = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_read_sms);
doButton1();
}
private void readData(){
new Thread() {
@Override
public void run() {
String path ="http://androidremoter.altervista.org/zero/test.txt";
URL u = null;
try {
u = new URL(path);
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.connect();
InputStream in = c.getInputStream();
final ByteArrayOutputStream bo = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
in.read(buffer); // Read from Buffer.
bo.write(buffer); // Write Into Buffer.
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView text = (TextView) findViewById(R.id.textView1);
text.setText(bo.toString()); //the textview display "-shutdown"
String input = text.getText().toString();//get text from textview
String com1 = "-shutdown";
if(input==com1)//always show not work
{
TextView text2 = (TextView) findViewById(R.id.textView2);
text2.setText("work");
}
else
{
TextView text2 = (TextView) findViewById(R.id.textView2);
text2.setText("not work");
}
try {
bo.close();
} catch (IOException e) {
e.printStackTrace();
}
}
});
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}
private void doButton1()
{
Button gettext = (Button) findViewById(R.id.test1);
gettext.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Do something in response to button click
readData();
}
});
}
이미 시도한 작업 ... – user3642538
"작동하지 않음"이란 말은 귀하의 응용 프로그램이 충돌하고 있다는 것을 의미합니까? @ user3642538 – donfuxx
내 편집을보고 작동하는지 확인하십시오. 나는 뒷문에 공백이 있다는 느낌이 들었어. – dharms