如何使用从远程通知创build的本地通知来激活活动

我已经成功创build了一个启动活动的本地通知,但由于某种原因,当从远程通知处理程序中创build此本地通知时,当用户点击本地通知时,活动不会启动。 没有错误或exception似乎被抛出。

以下是创build本地通知的代码。 注意我正在使用Xamarin。 我想知道它是否可能以某种方式与权限相关(远程通知处理程序可能无法创build启动活动的意图?)。

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()); } 

Solutions Collecting From Web of "如何使用从远程通知创build的本地通知来激活活动"

我仍然不确定我的初始尝试有什么问题,但我确实发现可以通过将Intent更改为使用组件名称而不是操作或活动types来修复它:

  private void SendNotification() { var nMgr = (NotificationManager)this.GetSystemService(NotificationService); var notification = new Notification(Resource.Drawable.AppIcon, "Incoming Dart"); var intent = new Intent(); intent.SetComponent(new ComponentName(this, "dart.androidapp.ContactsActivity")); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, 0); notification.SetLatestEventInfo(this, "You've got something to read", "You have received a message", pendingIntent); nMgr.Notify(0, notification); } 

你应该可以用typeof(…)来调用它。 您首先发布的代码与后者完全不同。 试试如果这对你有用:

 private void SendNotification() { var nMgr = (NotificationManager)this.GetSystemService(NotificationService); var notification = new Notification(Resource.Drawable.AppIcon, "Incoming Dart"); var intent = new Intent(this, typeof(ContactsActivity)); //intent.SetComponent(new ComponentName(this, "dart.androidapp.ContactsActivity")); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, 0); notification.SetLatestEventInfo(this, "You've got something to read", "You have received a message", pendingIntent); nMgr.Notify(0, notification); } 

你好,安德鲁我波纹pipe工作正常

 NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.ic_launcher, "Hello Chitta!", System.currentTimeMillis()); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("message/rfc822"); intent.putExtra(Intent.EXTRA_EMAIL , new String[]{"jdsjdjbdf@gmail.com"}); intent.putExtra(Intent.EXTRA_SUBJECT, "Hello CR!"); intent.putExtra(Intent.EXTRA_TEXT , "This is the body of email"); PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); notification.setLatestEventInfo(getApplicationContext(), "Send an e-mail", "Ha ha", pendingIntent); notificationManager.notify(742134, notification); 

在谈论别的什么?