我在这个操作上遇到了一些麻烦。我有一个更新一些东西的小部件。当收到短信时,我想在收到后更新它。我写了一个 BrodCastReceiver 类,但它在到达之前更新。
public class SmsReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
ComponentName name = new ComponentName(context, Randomnuberwidget.class);
int [] ids = AppWidgetManager.getInstance(context).getAppWidgetIds(name);
Intent update = new Intent();
update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
update.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
context.sendBroadcast(update);
}