<legend id='yYRB2'><style id='yYRB2'><dir id='yYRB2'><q id='yYRB2'></q></dir></style></legend>
  • <tfoot id='yYRB2'></tfoot>

        <small id='yYRB2'></small><noframes id='yYRB2'>

        <i id='yYRB2'><tr id='yYRB2'><dt id='yYRB2'><q id='yYRB2'><span id='yYRB2'><b id='yYRB2'><form id='yYRB2'><ins id='yYRB2'></ins><ul id='yYRB2'></ul><sub id='yYRB2'></sub></form><legend id='yYRB2'></legend><bdo id='yYRB2'><pre id='yYRB2'><center id='yYRB2'></center></pre></bdo></b><th id='yYRB2'></th></span></q></dt></tr></i><div id='yYRB2'><tfoot id='yYRB2'></tfoot><dl id='yYRB2'><fieldset id='yYRB2'></fieldset></dl></div>
          <bdo id='yYRB2'></bdo><ul id='yYRB2'></ul>

        来自广播接收器的 android 更新小部件

        时间:2023-09-09
      1. <small id='5nXvd'></small><noframes id='5nXvd'>

                <bdo id='5nXvd'></bdo><ul id='5nXvd'></ul>
                <i id='5nXvd'><tr id='5nXvd'><dt id='5nXvd'><q id='5nXvd'><span id='5nXvd'><b id='5nXvd'><form id='5nXvd'><ins id='5nXvd'></ins><ul id='5nXvd'></ul><sub id='5nXvd'></sub></form><legend id='5nXvd'></legend><bdo id='5nXvd'><pre id='5nXvd'><center id='5nXvd'></center></pre></bdo></b><th id='5nXvd'></th></span></q></dt></tr></i><div id='5nXvd'><tfoot id='5nXvd'></tfoot><dl id='5nXvd'><fieldset id='5nXvd'></fieldset></dl></div>
                <tfoot id='5nXvd'></tfoot>
                  <tbody id='5nXvd'></tbody>
                  <legend id='5nXvd'><style id='5nXvd'><dir id='5nXvd'><q id='5nXvd'></q></dir></style></legend>
                  本文介绍了来自广播接收器的 android 更新小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I have an widget and I must update the widget when action android.media.RINGER_MODE_CHANGED occurs. I have the folowing broadcast receiver:

                  public void onReceive(Context context, Intent intent) {
                          AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context.getApplicationContext());
                          ComponentName thisWidget = new ComponentName(context.getApplicationContext(), ExampleAppWidgetProvider.class);
                          int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
                          if (appWidgetIds != null && appWidgetIds.length > 0) {
                              for (int widgetId : appWidgetIds) {
                                  RemoteViews remoteViews = new RemoteViews(context
                                          .getApplicationContext().getPackageName(),
                                          R.layout.widget1);
                                  appWidgetManager.updateAppWidget(widgetId, remoteViews);
                              }
                          }
                      }
                  

                  and this si code for my widget

                  public class ExampleAppWidgetProvider extends AppWidgetProvider {
                      DateFormat df = new SimpleDateFormat("hh:mm:ss");
                  
                      public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
                          final int N = appWidgetIds.length;
                          for (int i = 0; i < N; i++) {
                              int appWidgetId = appWidgetIds[i];
                              //my pudate widget code
                              appWidgetManager.updateAppWidget(appWidgetId, views);
                          }
                      }
                  }
                  
                  <receiver android:name=".ExampleAppWidgetProvider" android:label="demo widget">
                    <intent-filter>
                          <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                    </intent-filter>
                    <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget1_info" />
                  </receiver>
                  

                  so my problem is that even if the instruction appWidgetManager.updateAppWidget(widgetId, remoteViews); from my broadcast receiver is executed, the update method inside the widget is not executed. Does anybody knows why?

                  解决方案

                  it seems that AppWidgetProvider extends BroadcastReceiver so here is my code :

                  public class ExampleAppWidgetProvider extends AppWidgetProvider {
                      DateFormat df = new SimpleDateFormat("hh:mm:ss");
                  
                      public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
                          //my update code here
                      }
                  
                      @Override
                      public void onReceive(Context context, Intent intent) {
                          AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context.getApplicationContext());
                          ComponentName thisWidget = new ComponentName(context.getApplicationContext(), ExampleAppWidgetProvider.class);
                          int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
                          if (appWidgetIds != null && appWidgetIds.length > 0) {
                              onUpdate(context, appWidgetManager, appWidgetIds);
                          }
                      }
                  }
                  
                  <receiver android:name=".ExampleAppWidgetProvider" android:label="demo widget">
                      <intent-filter>
                          <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
                      </intent-filter>
                      <intent-filter>
                          <action android:name="android.media.RINGER_MODE_CHANGED"/>
                      </intent-filter>
                      <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget1_info"/>
                  </receiver>
                  

                  这篇关于来自广播接收器的 android 更新小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Android 小部件按钮停止工作 下一篇:如何使 Android 搜索栏平滑移动?

                  相关文章

                  1. <tfoot id='SXJir'></tfoot>
                  2. <i id='SXJir'><tr id='SXJir'><dt id='SXJir'><q id='SXJir'><span id='SXJir'><b id='SXJir'><form id='SXJir'><ins id='SXJir'></ins><ul id='SXJir'></ul><sub id='SXJir'></sub></form><legend id='SXJir'></legend><bdo id='SXJir'><pre id='SXJir'><center id='SXJir'></center></pre></bdo></b><th id='SXJir'></th></span></q></dt></tr></i><div id='SXJir'><tfoot id='SXJir'></tfoot><dl id='SXJir'><fieldset id='SXJir'></fieldset></dl></div>

                  3. <legend id='SXJir'><style id='SXJir'><dir id='SXJir'><q id='SXJir'></q></dir></style></legend>

                    <small id='SXJir'></small><noframes id='SXJir'>

                      • <bdo id='SXJir'></bdo><ul id='SXJir'></ul>