是的,你可以有你的小部件更新为C2DM(现GCM)进来,
一旦您的应用程序接收C2DM(或GCM)消息,你将不得不从您的服务器获取您的更新,或如果您将消息作为有效内容发送,并从本地存储,则从消息中检索它。然后,您将不得不为您的小部件启动更新服务,您可能已经在使用该服务。如果不知道更多关于您的应用的信息,就很难确切说明如何实现这一点。一般来说,小部件将有一个更新的服务。下面是一个通用的更新服务:
public static class UpdateService extends Service {
@Override
public void onStart(Intent intent, int startId) {
RemoteViews updateViews = buildUpdate(this);
// Push update for this widget to the home screen
ComponentName thisWidget = new ComponentName(this, Widget.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(thisWidget, updateViews);
}
public RemoteViews buildUpdate(Context context) {
// process the updated view here. Probably would pull data from DB and update views //accordingly
return updateViews;
}
}
我终于开始在这个项目上再次工作。感谢你的回答 – tdramble