1

I have simple widget for showing forecast and I am trying to update it after my request to the API I use is done. But I get this freaky error : "E/Finsky: [1] com.google.android.finsky.widget.a.onReceive(146): Refusing to update all widgets; need to narrow scope"

private void updateWidgets(Context context){
    Intent updateIntent = new Intent();
    updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    context.sendBroadcast(updateIntent);
}

I have tried to call this method in the activity, in the end of the service, or in a broadcast receiver(listening for broadcast from the service after its finished). Could anyone give me a suggestion what could I do wrong?

Widget class:

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    for(int i = 0; i<appWidgetIds.length; i++){

        int currentWidgetId = appWidgetIds[i];

        RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.weathy_widget_info);

       //Some other unrelated stuff

        appWidgetManager.updateAppWidget(currentWidgetId,views);

    }
}

The method triggers the update, but it wont update the widget, and I dont know what is the problem. Also will it be possible to be something with working with SQLite in the onUpdate()?

  • Possible duplicate of [Programmatically update widget from activity/service/receiver](http://stackoverflow.com/questions/3455123/programmatically-update-widget-from-activity-service-receiver) – Mike M. Oct 13 '16 at 22:13
  • Nope, I did tried most of these methods. The problem is that the mothod triggers the update. But it wont update the widget... – Martin Andonov Oct 13 '16 at 22:17
  • The code you have in your `updateWidgets()` method will not fire your `AppWidgetProvider`'s `onUpdate()` method. If you've altered `AppWidgetProvider`'s default behavior, you need to include your code in your question. Otherwise, it's just a matter of specifying your `AppWidgetProvider` class and the widget IDs on the broadcast `Intent`, as demonstrated in posts on the linked question. – Mike M. Oct 13 '16 at 22:22
  • @MikeM. Is it possible that I am doing something wrong, because the error I got int the question is gone now, but the widget is not updating. Only if I get a new instance on the home screen? Sorry if this sounds like stupid question but I am new in Android. I have only put intent filter in the manifest as it is required for "android.appwidget.action.APPWIDGET_UPDATE" thank you, for answering this fast! – Martin Andonov Oct 13 '16 at 22:38
  • That's the correct action. I would guess that maybe you're not attaching the correct IDs, or possibly with the wrong key. Make sure you're doing it like is shown in this answer there: http://stackoverflow.com/a/14256988. – Mike M. Oct 13 '16 at 22:46
  • 1
    @MikeM. I actually realized I have to read the answers few times to see where I am wrong. I was actually was setting as id a layout, that wasnt suppose to be there. It is working now just fine. Thank you – Martin Andonov Oct 13 '16 at 22:54

0 Answers0