AppWidgetProvider的继承

public class WlanWidget extends AppWidgetProvider{ 
 
RemoteViews remoteViews; 
AppWidgetManager appWidgetManager; 
ComponentName thisWidget; 
WifiManager wifiManager; 
 
public void onUpdate(Context context, AppWidgetManager appWidgetManager, 
        int[] appWidgetIds) { 
        Timer timer = new Timer(); 
        timer.scheduleAtFixedRate(new WlanTimer(context, appWidgetManager), 1, 10000); 
 
} 
 
 
private class WlanTimer extends TimerTask{ 
 
        RemoteViews remoteViews; 
        AppWidgetManager appWidgetManager; 
        ComponentName thisWidget; 
 
 
public WlanTimer(Context context, AppWidgetManager appWidgetManager) { 
 
        this.appWidgetManager = appWidgetManager; 
        remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); 
        thisWidget = new ComponentName(context, WlanWidget.class); 
        wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); 
 
 
} 
 
@Override 
public void run() { 
 
        remoteViews.setTextViewText(R.id.widget_textview, 
        wifiManager.getConnectionInfo().getSSID()); 
        appWidgetManager.updateAppWidget(thisWidget, remoteViews); 
} 
 
} 

 

为了更有效率可以使用

RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); 
ComponentName thisWidget = new ComponentName( context, WlanWidget.class ); 
remoteViews
.setTextViewText(R.id.widget_QCLevel, " " + qcPercentage); 
AppWidgetManager.getInstance( context ).updateAppWidget( thisWidget, remoteViews ); 
进行该井

你可能感兴趣的:(appwidget)