Android 3 - Connessione a server - 9

# HttpUrlConnection per leggere dal server - 2

# caricaNotizie.java

    		private String caricaNotizie() {
    			try {
    				URL url = new URL("http://www.fermimn.gov.it/?action=rss");
    				HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    				try {
    					String linea;
    					BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
    					while ((linea = in.readLine()) != null) {
    						if (linea.contains("<title>") && !linea.contains("NEWS</")) {
    							linea = linea.trim().replaceAll("<?title>", "");
    							publishProgress(linea);
    						}
    					}
    				}
    				catch (Exception e) {
    					return e.getMessage();
    				}
    				finally {
    					urlConnection.disconnect();
    				}
    			} catch (Exception ee) {
    				return ee.getMessage();
    			}

    			return null;
    		}

© Ing. Stefano Salvi - released under FDL licence