android 触发AppWidget上控件事件来更新AppWidget

 

思想:利用AppWidgetProvider里面的onReceive()事件接收广播来更新AppWidget。
步骤:
一、给AppWidget上的某个控件设置OnClickPendingIntent():

Intent UPintent=new Intent("zyf.test.widget.UP");     
           PendingIntent pendingIntentUp=PendingIntent.getBroadcast(context, 0, UPintent, 0);     
           views.setOnClickPendingIntent(R.id.widget_BT_Up, pendingIntentUp);    
Intent UPintent=new Intent("zyf.test.widget.UP");  
           PendingIntent pendingIntentUp=PendingIntent.getBroadcast(context, 0, UPintent, 0);  
           views.setOnClickPendingIntent(R.id.widget_BT_Up, pendingIntentUp);  
 

二、设置AppWidget的intent-filter:

     
                
                   
   
                   
                  
       
     
              
     
   
  
             
                
 
                
               
       
  
           
     
 
 

三、在onReceive()中判断;

super.onReceive(context, intent);     
       if(intent.getAction().equals("zyf.test.widget.UP")){     
   //处理     
}  

你可能感兴趣的:(Android)