Android 打开网络连接

【Android 打开网络连接】今日长缨在手,何时缚住苍龙。这篇文章主要讲述Android 打开网络连接相关的知识,希望能为你提供帮助。
使用url打开网络连接

String urlString = "http://"+et_url.getText()+""; if(urlString.length()> 0){ try { String line = ""; URL url = new URL(urlString); URLConnection urlConnection = url.openConnection(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); while ((line = bufferedReader.readLine())!=null){ if(line.indexOf("a href")> =0) tv_url.setText(line); } bufferedReader.close(); urlConnection.getInputStream().close(); } catch (Exception e) { e.printStackTrace(); tv_url.setText(e.toString()); } }


    推荐阅读