Xamarin Android Wear:获取当前点击的Notification ID
Xamarin Android Wear: Get the currently clicked Notification ID
我尝试使用PutExtra & GetIntExtra,但是通知id总是被最后一个通知覆盖,所有的通知值都是相同。请告诉我如何解决,
提前致谢!
Intent actionIntent = new Intent(this, typeof(ConfirmActivity));
actionIntent.PutExtra("NOTIFY_ID", 1);
PendingIntent actionPendingIntent = PendingIntent.GetActivity(this, 0, actionIntent, PendingIntentFlags.UpdateCurrent);
NotificationCompat.Action action = new NotificationCompat.Action.Builder(Resource.Drawable.ic_done_white_64dp_1x,
this.Resources.GetString(Resource.String.confirm), actionPendingIntent)
.Build();
var notification = new NotificationCompat.Builder(this)
.SetContentTitle("1111")
.SetContentText("1111111111111111111111")
.SetSmallIcon(Resource.Drawable.Icon).Extend(new NotificationCompat.WearableExtender().AddAction(action)).Build();
var manager = NotificationManagerCompat.From(this);
manager.Notify(1, notification);
Intent actionIntent2 = new Intent(this, typeof(ConfirmActivity));
actionIntent2.PutExtra("NOTIFY_ID", 2);
PendingIntent actionPendingIntent2 = PendingIntent.GetActivity(this, 0, actionIntent2, PendingIntentFlags.UpdateCurrent);
NotificationCompat.Action action2 = new NotificationCompat.Action.Builder(Resource.Drawable.ic_done_white_64dp_1x,
this.Resources.GetString(Resource.String.confirm), actionPendingIntent2)
.Build();
var notification2 = new NotificationCompat.Builder(this)
.SetContentTitle("2222")
.SetContentText("22222222222222222222")
.SetSmallIcon(Resource.Drawable.Icon).Extend(new NotificationCompat.WearableExtender().AddAction(action2)).Build();
manager.Notify(2, notification2);
=================================
[Activity(Label = "ConfirmActivity")]
public class ConfirmActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Confirm);
Intent intent = this.Intent;
int NOTIFY_ID = intent.GetIntExtra("NOTIFY_ID", 0); //always 2
}
}
您可能需要检查一下 thread。它建议将 Bundle 与 PendingIntent 一起传递给下一个 Activity.
Bundle bundle = new Bundle();
bundle.putString("Any String");
NotificationManager notifManager = (NotificationManager) this.getSystemService(this.NOTIFICATION_SERVICE);
int uniqueInteger = //create a unique Integer
int icon = R.drawable.ic_launcher;
NotificationCompat2.Builder mNotification = new NotificationCompat2.Builder(this).setSmallIcon(icon)
.setContentTitle(contentTitle).setContentIntent(getPendingIntent(bundle, uniqueInteger));
mNotification.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
mNotification.setAutoCancel(true);
notifManager.notify(uniqueInteger, mNotification.build());
以下是一些可能有帮助的相关 SO 帖子:
- How to check which notification id is clicked?
我尝试使用PutExtra & GetIntExtra,但是通知id总是被最后一个通知覆盖,所有的通知值都是相同。请告诉我如何解决,
提前致谢!
Intent actionIntent = new Intent(this, typeof(ConfirmActivity));
actionIntent.PutExtra("NOTIFY_ID", 1);
PendingIntent actionPendingIntent = PendingIntent.GetActivity(this, 0, actionIntent, PendingIntentFlags.UpdateCurrent);
NotificationCompat.Action action = new NotificationCompat.Action.Builder(Resource.Drawable.ic_done_white_64dp_1x,
this.Resources.GetString(Resource.String.confirm), actionPendingIntent)
.Build();
var notification = new NotificationCompat.Builder(this)
.SetContentTitle("1111")
.SetContentText("1111111111111111111111")
.SetSmallIcon(Resource.Drawable.Icon).Extend(new NotificationCompat.WearableExtender().AddAction(action)).Build();
var manager = NotificationManagerCompat.From(this);
manager.Notify(1, notification);
Intent actionIntent2 = new Intent(this, typeof(ConfirmActivity));
actionIntent2.PutExtra("NOTIFY_ID", 2);
PendingIntent actionPendingIntent2 = PendingIntent.GetActivity(this, 0, actionIntent2, PendingIntentFlags.UpdateCurrent);
NotificationCompat.Action action2 = new NotificationCompat.Action.Builder(Resource.Drawable.ic_done_white_64dp_1x,
this.Resources.GetString(Resource.String.confirm), actionPendingIntent2)
.Build();
var notification2 = new NotificationCompat.Builder(this)
.SetContentTitle("2222")
.SetContentText("22222222222222222222")
.SetSmallIcon(Resource.Drawable.Icon).Extend(new NotificationCompat.WearableExtender().AddAction(action2)).Build();
manager.Notify(2, notification2);
=================================
[Activity(Label = "ConfirmActivity")]
public class ConfirmActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Confirm);
Intent intent = this.Intent;
int NOTIFY_ID = intent.GetIntExtra("NOTIFY_ID", 0); //always 2
}
}
您可能需要检查一下 thread。它建议将 Bundle 与 PendingIntent 一起传递给下一个 Activity.
Bundle bundle = new Bundle();
bundle.putString("Any String");
NotificationManager notifManager = (NotificationManager) this.getSystemService(this.NOTIFICATION_SERVICE);
int uniqueInteger = //create a unique Integer
int icon = R.drawable.ic_launcher;
NotificationCompat2.Builder mNotification = new NotificationCompat2.Builder(this).setSmallIcon(icon)
.setContentTitle(contentTitle).setContentIntent(getPendingIntent(bundle, uniqueInteger));
mNotification.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
mNotification.setAutoCancel(true);
notifManager.notify(uniqueInteger, mNotification.build());
以下是一些可能有帮助的相关 SO 帖子:
- How to check which notification id is clicked?