new AsyncTask() {
@Override
protected String doInBackground(String... params) {
try {
URI url = new URI(params[0]);
URLConnection connection=url.openConnection();//这行的openConnection显示为红色
long total = connection.getContentLength();
InputStream is = connection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
StringBuilder sb = new StringBuilder();
while ((line=br.readLine())!=null){
sb.append(line);
publishProgress((float)sb.toString().length()/total);
}
br.close();
is.close();
return sb.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
android开发中url的openConnection()不能被IDE识别怎么办?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-