else if (v.getId() == R.id.update) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
URL url = new URL("http://darkliteempire.gaming.multiplay.co.uk/testdownload.txt");
//create the new connection
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
//set up some things on the connection
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
//and connect!
urlConnection.connect();
//set the path where we want to save the file
//in this case, going to save it on the root directory of the
//sd card.
File SDCardRoot = new File("/sdcard/"+"download/");
//create a new file, specifying the path, and the filename …Run Code Online (Sandbox Code Playgroud) 对,我认为,就这一点而言,你应该认为我是一个完整的菜鸟,我在我的脑海里.
我试图通过几个部分教程来拼凑我对此的理解,每个教程都处理我想要做的不同方面.
它的长短不一,我想要做的就是从URL中读取文本以在文本视图中显示,我的理解是,自3.0更新以来,我需要一个AsyncTask来执行此操作.
任何关于我出错的帮助都会很棒,因为我不明白是什么导致了错误以及如何解决.
我知道doInBackground的try和catch中包含的代码在3.0更新之前就可以自行运行.是否需要修改它以使用Async,但我不知道.
我还想象,一旦这个问题被分类,可能会出现其他问题,如果有人发现一些明显的东西,如果你能指出它我将不胜感激.
String Event;
TextView eventText;
TextView titleText;
String HTML;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newevent);
titleText = (TextView) findViewById(R.id.Title);
eventText = (TextView) findViewById(R.id.Event);
new eventupdate().execute();
}
public class eventupdate extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... url) {
try {
Thread.sleep(4000);
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet(
"http://masterzangetsu.eu/Apps/rocksoctest"); // URL!
HttpResponse response = httpClient.execute(httpGet,
localContext);
String result = "";
BufferedReader reader = new …Run Code Online (Sandbox Code Playgroud)