【发布时间】:2014-01-14 13:37:43
【问题描述】:
我已经成功地创建了一个启动活动的本地通知,但是由于某种原因,当这个本地通知被创建时从远程通知的处理程序中当本地通知被启动时,活动没有启动被用户点击。似乎没有抛出任何错误或异常。
以下是创建本地通知的代码。注意我正在使用 Xamarin。 我想知道它是否可能与权限相关(远程通知处理程序可能无法创建启动活动的意图?)。
private void CreateNotification(string title, string desc) {
var uiIntent = new Intent(this, typeof(ConversationActivity));
var stackBuilder = TaskStackBuilder.Create(this);
stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(ConversationActivity)));
stackBuilder.AddNextIntent(uiIntent);
PendingIntent pendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);
var notification = new NotificationCompat.Builder(this)
.SetAutoCancel(true) // Remove the notification once the user touches it
.SetContentIntent(pendingIntent)
.SetContentTitle(title)
.SetSmallIcon(Resource.Drawable.AppIcon)
.SetContentText(desc)
.SetDefaults((int)(NotificationDefaults.Sound | NotificationDefaults.Vibrate))
;
// Set the notification info
// we use the pending intent, passing our ui intent over which will get called
// when the notification is tapped.
var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
notificationManager.Notify(1, notification.Build());
}
【问题讨论】:
标签: c# android notifications push-notification xamarin