private static Intent CreateIntent(int notificationId, LocalNotificationAction notificationAction, bool launchActivity = false) { Intent intent = null; if (launchActivity) { // Set activity as receiver intent = typeof(Activity).IsAssignableFrom(LocalNotifications.NotificationActivityType) ? new Intent(Application.Context, LocalNotifications.NotificationActivityType) : Application.Context.PackageManager.GetLaunchIntentForPackage(Application.Context.PackageName); } else { intent = new Intent(LocalNotifications.NotificationAction); // Find the broadcast receiver associated with the intent var packageManager = Application.Context.PackageManager; var match = packageManager.QueryBroadcastReceivers(intent, 0).FirstOrDefault(); if (match != null) { // Explicitly set the component to receive this intent intent.SetComponent(new ComponentName(match.ActivityInfo.ApplicationInfo.PackageName, match.ActivityInfo.Name)); } } if (notificationAction != null) { intent.PutExtra(LocalNotification.NotificationId, notificationId); intent.PutExtra(LocalNotification.ActionSetId, notificationAction.ActionSetId); intent.PutExtra(LocalNotification.ActionId, notificationAction.Id); intent.PutExtra(LocalNotification.ActionParameter, notificationAction.Parameter); } return(intent); }
private static PendingIntent CreatePendingIntent(int notificationId, LocalNotificationAction action) { var intent = CreateIntent(notificationId, action); return(PendingIntent.GetBroadcast(Application.Context, GetRandomId(), intent, PendingIntentFlags.UpdateCurrent)); }
private static PendingIntent CreateActivityPendingIntent(int notificationId, LocalNotificationAction action) { var intent = CreateIntent(notificationId, action, launchActivity: true); return(PendingIntent.GetActivity(Application.Context, GetRandomId(), intent, PendingIntentFlags.UpdateCurrent)); }