la questione è molto semplice, se uso i link commentati mi da errore. cosa devo fare?
codice:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.filippogiuliani.trewidget;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import org.apache.http.util.ByteArrayBuffer;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.text.format.Time;
import android.widget.RemoteViews;
/**
*
* @author filippogiuliani
*/
public class Widget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
Time time = new Time();
time.setToNow();
String page1 = null, page2 = null, page3 = null;
try {
//URL url = new URL("http://portale3.tre.it/ccmmobile/?context=cn=beneficiotariffariotariffasuper,cn=selfcare&dvc=HI");
URL url = new URL("http://www.filippogiuliani.net/external/pagina11.htm");
page1 = this.getPage(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
if (page1 != null)
{
views.setTextViewText(R.id.ricarica, this.getParameter(page1, "Stato ricarica:", "</", false));
views.setTextViewText(R.id.tariffa, this.getParameter(page1, "Stato beneficio:", "</", false));
}
try {
//URL url = new URL("http://portale3.tre.it/ccmmobile/?context=cn=infocosti,cn=selfcare&dvc=HI");
URL url = new URL("http://www.filippogiuliani.net/external/pagina21.htm");
page2 = this.getPage(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
if (page2 != null)
{
views.setTextViewText(R.id.credito, "Credito: " + this.getParameter(page2, "Credito Standard:", "€</", true) + "€");
views.setTextViewText(R.id.autoricarica, "Auto Ricarica Maturata: " + this.getParameter(page2, "Totale Autoricarica maturata nel mese", "€</", true) + "€");
}
try {
//URL url = new URL("http://portale3.tre.it/ccmmobile/?context=cn=infocostioption,cn=selfcare&optionId=PS000095_PRD&dvc=HI");
URL url = new URL("http://www.filippogiuliani.net/external/pagina31.htm");
page3 = this.getPage(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
if (page3 != null)
{
views.setTextViewText(R.id.traffico, "Traffico Residuo: " + this.getParameter(page3, "Traffico residuo", "MB</", true) + "MB");
}
views.setTextViewText(R.id.update, "Last Update: " + time.monthDay + "/" + time.month + "/" + time.year + " " + time.hour + ":" + time.minute);
//views.setTextViewText(R.id.credito, "Qualsiasi cosa");
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
private String getParameter(String string, String string2, String string3, boolean b) {
if (string.indexOf(string2) != -1)
{
String returnString = string.substring(string.indexOf(string2));
returnString = returnString.substring(0, returnString.indexOf(string3));
if(b)
while (returnString.indexOf(">") != -1 && returnString.indexOf("<") != -1)
returnString = returnString.substring(returnString.indexOf(">") + 1);
return returnString;
}
else
return null;
}
private String getPage(URL url) {
try{
URLConnection ucon = url.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while((current = bis.read()) != -1){
baf.append((byte)current);
}
return new String(baf.toByteArray());
}
catch(Exception e) {
return null;
}
}
}