`
wang_peng1
  • 浏览: 3902168 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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 ); 
进行该井

分享到:
评论
1 楼 ghwcn 2011-08-31  

相关推荐

Global site tag (gtag.js) - Google Analytics