我想从 web 目录文件列表中显示 listview。如何在android中访问web目录文件列表。
例如: http: //mp3.com/song/
这是网络目录。
公共类 MainActivity 扩展 Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// JSONObject json = JSONfunctions
// .getJSONfromURL("http://selangorbn.fm/song/");
// Log.d("TAG", "json" + json);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
new Getparse().execute();
}
private void parse() throws IOException {
String line = null, response;
URL url = new URL("http://selangorbn.fm/song/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
BufferedReader rd = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
while (rd.readLine() != null) {
line += rd.readLine();
}
System.out.println(line);
}
public class Getparse extends AsyncTask<Void, Void, integer> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
@Override
protected integer doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
parse();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(integer result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
} 获得空值。