void SetContentIntent(IPlatformNotificationBuilder builder, ToastId toastId)
 {
     builder.SetContentIntent(
         builder.GetForceOpenAppOnNotificationTap()
         ? CreateLaunchIntent(builder, toastId)
         : CreateContentOrDeleteIntent(IntentConstants.KTapped, builder, toastId));
 }
 public Notification(
     IPlatformNotificationBuilder notificationBuilder,
     IIntentManager intentManager,
     IAndroidNotificationManager androidNotificationManager)
 {
     this.notificationBuilder        = notificationBuilder ?? throw new ArgumentNullException(nameof(notificationBuilder));
     this.intentManager              = intentManager;
     this.androidNotificationManager = androidNotificationManager;
 }
        static PendingIntent CreateContentOrDeleteIntent(string action, IPlatformNotificationBuilder builder, ToastId toastId)
        {
            var intent = new Intent(action);

            toastId.ToIntent(intent);
            builder.AddCustomArgsTo(intent);

            var result = PendingIntent.GetBroadcast(Application.Context, toastId.GetPersistentHashCode(), intent, 0)
                         ?? throw new InvalidOperationException(ErrorStrings.KBroadcastError);

            return(result);
        }
        public PendingIntent RegisterToShowWithDelay(IPlatformNotificationBuilder builder, ToastId toastId)
        {
            if (builder.UsingCustomContentIntent == false)
            {
                SetContentIntent(builder, toastId);
            }

            var notification = builder.Build();
            var intent       = new Intent(IntentConstants.KScheduled);

            toastId.ToIntent(intent);
            intent.PutExtra(IntentConstants.KNotification, notification);
            var pendingIntent = PendingIntent.GetBroadcast(Application.Context, toastId.GetPersistentHashCode(), intent, PendingIntentFlags.CancelCurrent)
                                ?? throw new InvalidOperationException(ErrorStrings.KBroadcastError);

            return(pendingIntent);
        }
        PendingIntent CreateLaunchIntent(IPlatformNotificationBuilder builder, ToastId toastId)
        {
            var packageManager = Application.Context.PackageManager;
            var intent         = packageManager?.GetLaunchIntentForPackage(options.PackageName);

            if (intent == null)
            {
                throw new InvalidOperationException("can't get launch intent");
            }
            intent.AddFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
            toastId.ToIntent(intent);
            builder.AddCustomArgsTo(intent);
            var result = PendingIntent.GetActivity(Application.Context, toastId.GetPersistentHashCode(), intent, PendingIntentFlags.UpdateCurrent)
                         ?? throw new InvalidOperationException(ErrorStrings.KBroadcastError);

            return(result);
        }
        public TaskCompletionSource <NotificationResult> RegisterToShowImmediatly(IPlatformNotificationBuilder builder, ToastId toastId)
        {
            var(cdi, cci) = (builder.UsingCustomDeleteIntent, builder.UsingCustomContentIntent);
            TaskCompletionSource <NotificationResult> result = new TaskCompletionSource <NotificationResult>();

            if (cdi == false)
            {
                builder.SetDeleteIntent(CreateContentOrDeleteIntent(IntentConstants.KDismissed, builder, toastId));
            }
            if (cci == false)
            {
                SetContentIntent(builder, toastId);
            }

            lock (mutex)
                tasksByNotificationId.Add(toastId, result);
            if (cci)
            {
                result.TrySetResult(NotificationResult.Unknown);
            }
            return(result);
        }
Пример #7
0
 public Notification(ToastContent toastContent, IPlatformNotificationBuilder notificationBuilder)
     : this(toastContent.GetXml(), notificationBuilder)
 {
 }
Пример #8
0
 public Notification(XmlDocument xmlDocument, IPlatformNotificationBuilder notificationBuilder)
 {
     this.xmlDocument         = xmlDocument;
     this.notificationBuilder = notificationBuilder;
 }
Пример #9
0
 public Notification(IPlatformNotificationBuilder builder, INotificationReceiver notificationReceiver, IPermission permission)
 => (this.builder, this.notificationReceiver, this.permission) = (builder, notificationReceiver, permission);