Câu hỏi 1: mình đọc file rss như bên dưới nhưng không đọc được, mong được chỉ giáo.?
Câu hỏi 2: Làm sao để saxparser rss ???
package net.tiennguyen.tiennguyen.docxml;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
runOnUiThread(new Runnable() {
@Override
public void run() {
new LoadXML().execute();
}
});
}
private class LoadXML extends AsyncTask<String,Integer,String>{
@Override
protected String doInBackground(String... params) {
String text = docNoiDung_Tu_URL("http://dantri.com.vn/trangchu.rss");
return text;
}
@Override
protected void onPostExecute(String s) {
Toast.makeText(MainActivity.this,s,Toast.LENGTH_LONG).show();
}
}
private static String docNoiDung_Tu_URL(String theUrl)
{
StringBuilder content = new StringBuilder();
try
{
// create a url object
URL url = new URL(theUrl);
// create a urlconnection object
URLConnection urlConnection = url.openConnection();
// wrap the urlconnection in a bufferedreader
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line;
// read from the urlconnection via the bufferedreader
while ((line = bufferedReader.readLine()) != null)
{
content.append(line + "\n");
}
bufferedReader.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return content.toString();
}
}