使用RemoteViews从BroadcastReceiver更新更多小部件

时间:2013-08-30 16:14:25

标签: android widget broadcastreceiver remoteview

我按照以下步骤操作:https://stackoverflow.com/a/18236800/824963以使我的广播接收器正常工作。

实际上所有的报警管理器都工作正常,但每次调用onReceive时都会使用相同的数据更新所有小部件

public class AlarmManagerBroadcastReceiver extends BroadcastReceiver
{
    @Override
    public void onReceive(final Context context, Intent intent)
    {       
        final String address = intent.getStringExtra("mykey");
        ...
        final RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); 

        // downloading data
        ...
        // decoding data
        ...

        remoteViews.setTextViewText(R.id.mykey, newvalue);

        ComponentName thiswidget = new ComponentName(context, AppWidgetProvider.class);
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        appWidgetManager.updateAppWidget(thiswidget, remoteViews);
    }
}

0 个答案:

没有答案