查看通知时,我无法获取 Intent 的 Extras 数据。以下是我如何构建通知,以及我传递给它的意图数据。有什么问题吗?我已经看到其他与此非常相似的示例似乎有效。
protected override void OnMessage(Context context, Intent intent)
{
// irrelevant stuff removed
string title = "Notification";
string message = "The Notification Message";
Bundle valuesForActivity = new Bundle();
valuesForActivity.PutInt("panelId", (int)panelId);
Intent pendingIntent = new Intent(context, typeof (TabContainer));
pendingIntent.PutExtras(valuesForActivity);
pendingIntent.SetFlags(ActivityFlags.SingleTop);
pendingIntent.PutExtra("panelId", (int)panelId);
//neither PendingIntentFlags.CancelCurrent or PendingIntentFlags.UpdateCurrent works
PendingIntent resultPendingIntent = PendingIntent.GetActivity(context, 0, pendingIntent, PendingIntentFlags.CancelCurrent);
//PendingIntent resultPendingIntent = PendingIntent.GetActivity(context, 0, pendingIntent, PendingIntentFlags.UpdateCurrent);
var builder = new NotificationCompat.Builder(context);
builder.SetContentTitle(title);
builder.SetAutoCancel(true);
builder.SetSmallIcon(Resource.Drawable.icon24);
builder.SetLargeIcon(BitmapFactory.DecodeStream(context.Resources.OpenRawResource(Resource.Drawable.icon96)));
builder.SetContentText(message);
builder.SetContentIntent(resultPendingIntent);
builder.SetTicker(title);
builder.SetVibrate(new long[] { 100, 200, 300 });
var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
notificationManager.Notify(1, builder.Build());
}
然后在 TabContainer 活动中,我从来没有我需要的数据:
public class TabContainer : TabActivity
{
protected override void OnResume()
{
base.OnResume();
int panelId = Intent.GetIntExtra("panelId", 0); // always 0
var extras = Intent.Extras; // always null
}
}