コード例 #1
0
        public override void OnReceive(Context context, Intent intent)
        {
            // When the user clicks the notification, SecondActivity will start up.
            Intent resultIntent = new Intent(context, typeof(MainActivity));

            // Construct a back stack for cross-task navigation:
            Android.App.TaskStackBuilder stackBuilder = Android.App.TaskStackBuilder.Create(context);
            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
            stackBuilder.AddNextIntent(resultIntent);

            // Create the PendingIntent with the back stack:
            PendingIntent resultPendingIntent =
                stackBuilder.GetPendingIntent(0, PendingIntentFlags.UpdateCurrent);

            // Build the notification:
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                                                 .SetAutoCancel(true)                                                                         // Dismiss from the notif. area when clicked
                                                 .SetContentIntent(resultPendingIntent)                                                       // Start 2nd activity when the intent is clicked.
                                                 .SetContentTitle("GREATER Campaign")                                                         // Set its title
                                                 .SetNumber(count)                                                                            // Display the count in the Content Info
                                                 .SetSmallIcon(Resource.Drawable.icon)                                                        // Display this icon
                                                 .SetContentText(String.Format(
                                                                     "Prayer Guide Reminder.  Pray for the GREATER campaign today.", count)); // The message to display.

            // Finally, publish the notification:
            NotificationManager notificationManager =
                (NotificationManager)context.GetSystemService(Context.NotificationService);

            notificationManager.Notify(100, builder.Build());
        }
        private void SendNotification(string notificationDetails)
        {
            Intent notificationIntent = new Intent(ApplicationContext, typeof(MainActivity));

            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);

            stackBuilder.AddParentStack(Class.FromType(typeof(MainActivity)));

            stackBuilder.AddNextIntent(notificationIntent);

            PendingIntent notificationPendingIntent = stackBuilder.GetPendingIntent(0, PendingIntentFlags.UpdateCurrent);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

            builder.SetSmallIcon(Resource.Drawable.Icon)
            .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.Icon))
            .SetColor(Color.Red)
            .SetContentTitle(notificationDetails)
            .SetContentText(GetString(Resource.String.geofence_transition_notification_text))
            .SetContentIntent(notificationPendingIntent);

            builder.SetAutoCancel(true);

            NotificationManager mNotificationManager =
                (NotificationManager)GetSystemService(Context.NotificationService);

            mNotificationManager.Notify(0, builder.Build());
        }
コード例 #3
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            if (intent == null)
            {
                return(StartCommandResult.NotSticky);
            }

            if (intent.Action == ACTION_STOP)
            {
                Stop();
                return(StartCommandResult.NotSticky);
            }
            else if (intent.Action == ACTION_START)
            {
                string         host          = intent.GetStringExtra(EXTRA_HOST);
                int            port          = intent.GetIntExtra(EXTRA_PORT, 1704);
                EBroadcastMode broadcastMode = (EBroadcastMode)intent.GetIntExtra(EXTRA_BROADCAST_MODE, (int)EBroadcastMode.Media);

                Intent stopIntent = new Intent(this, typeof(SnapclientService));
                stopIntent.SetAction(ACTION_STOP);
                PendingIntent PiStop = PendingIntent.GetService(this, 0, stopIntent, 0);

                NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
                                                     .SetSmallIcon(Resource.Drawable.ic_media_play)
                                                     .SetTicker("Snap.Net.Broadcast started")
                                                     .SetContentTitle("Snap.Net Broadcast")
                                                     .SetContentText("Snap.Net.Broadcast is running...")
                                                     .SetContentInfo(string.Format("{0}:{1}", host, port))
                                                     .SetStyle(new NotificationCompat.BigTextStyle().BigText("Snap.Net.Broadcast is running..."))
                                                     .AddAction(Resource.Drawable.ic_media_stop, "Stop", PiStop);

                Intent resultIntent = new Intent(this, typeof(MainActivity));

                TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);
                stackBuilder.AddParentStack(Class.FromType(typeof(MainActivity)));

                stackBuilder.AddNextIntent(resultIntent);
                PendingIntent resultPendingIntent =
                    stackBuilder.GetPendingIntent(
                        0,
                        PendingIntentFlags.UpdateCurrent
                        );

                builder.SetContentIntent(resultPendingIntent);
                Notification notification = builder.Build();

                StartForeground(NOTIFICATION_CHANNEL, notification);

                m_MediaProjection =
                    m_MediaProjectionManager.GetMediaProjection((int)Result.Ok,
                                                                intent.GetParcelableExtra(EXTRA_RESULT_DATA) as Intent);

                _Start(host, port, broadcastMode);

                return(StartCommandResult.Sticky);
            }

            return(StartCommandResult.NotSticky);
        }
コード例 #4
0
        private static Notification GetNotification(Context ctx, int sessionId, NotificationOption not)
        {
            WorkshopDetail session = null;

            if (not.isWorkshop)
            {
                session = Services.Workshop.GetWorkshopFromBookingLocal(sessionId);
            }
            else
            {
                session = Services.Session.GetSession(sessionId);
            }

            var prefix = (not.isWorkshop) ? "" : "Session with ";

            Notification.Builder mBuilder =
                new Notification.Builder(ctx)
                .SetSmallIcon(Resource.Drawable.notificationIcon)
                .SetContentTitle(prefix + session.Title)
                .SetContentText(session.Time + " - " + session.DateHumanFriendly)
                .SetAutoCancel(true)
                .SetColor(ctx.Resources.GetColor(Resource.Color.primary))
                .SetDefaults(NotificationDefaults.All)
                .SetStyle(
                    new Notification.BigTextStyle().SetSummaryText(session.Title)
                    .BigText(session.Time + " - " + session.DateHumanFriendly + System.Environment.NewLine +
                             session.Room));
            try
            {
                Looper.Prepare();
            }
            catch (System.Exception ex) { }

            Intent resultIntent = new Intent(ctx, new ViewSessionActivity().Class);

            if (not.isWorkshop)
            {
                resultIntent = new Intent(ctx, new ViewWorkshopActivity().Class);
            }
            resultIntent.PutExtra("Id", sessionId);
            resultIntent.PutExtra("IsBooking", true);

            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(ctx);

            stackBuilder.AddParentStack(new ViewWorkshopActivity().Class);
            stackBuilder.AddNextIntent(resultIntent);
            int           identifier          = (not.isWorkshop) ? 1 : 0;
            int           notificationId      = Integer.ParseInt(identifier + sessionId.ToString() + not.mins);
            PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(notificationId, PendingIntentFlags.UpdateCurrent);

            mBuilder.SetContentIntent(resultPendingIntent);
            return(mBuilder.Build());
        }
コード例 #5
0
 void CreateNotification(PushNoticationMessage pushMessage)
 {
     try
     {
         // Get the notifications manager:
         NotificationManager notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
         // Instantiate the notification builder:
         //TODO: Get the Name of  the App from Manifest
         Notification.Builder builder = new Notification.Builder(this)
                                        .SetContentTitle("Quick Task")
                                        .SetContentText(pushMessage.Title)
                                        .SetAutoCancel(true)
                                        .SetSmallIcon(Resource.Drawable.icon)
                                        .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.icon));
         builder.SetVisibility(NotificationVisibility.Public);
         builder.SetPriority((int)NotificationPriority.High);
         builder.SetCategory(Notification.CategoryMessage);
         //Setup an intent for the Main Activity:
         Intent secondIntent = new Intent(this, typeof(MainActivity));
         secondIntent.PutExtra("recdMessage", Settings.Current.LastMessage);
         // Pressing the Back button in SecondActivity exits the app:
         Android.App.TaskStackBuilder stackBuilder = Android.App.TaskStackBuilder.Create(this);
         // Add the back stack for the intent:
         stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
         // Push the intent (that starts SecondActivity) onto the stack. The
         // pending intent can be used only once (one shot):
         stackBuilder.AddNextIntent(secondIntent);
         const int     pendingIntentId = 0;
         PendingIntent pendingIntent   = stackBuilder.GetPendingIntent(pendingIntentId, PendingIntentFlags.OneShot);
         builder.SetContentIntent(pendingIntent);
         // Build the notification:
         Notification notification = builder.Build();
         notification.Defaults |= NotificationDefaults.Sound;
         // Notification ID used for all notifications in this app.
         // Reusing the notification ID prevents the creation of
         // numerous different notifications as the user experiments
         // with different notification settings -- each launch reuses
         // and updates the same notification.
         const int notificationId = 6;
         // Launch notification:
         notificationManager.Notify(notificationId, notification);
         Log.Info(AppConstants.TAG, "Local Notification Sent");
     }
     catch (Exception ex)
     {
         Log.Info(AppConstants.TAG, "Local Notify Failed with " + ex.Message);
     }
 }
コード例 #6
0
        public void Notify(string title, string body, Dictionary <string, string> data)
        {
            Intent intent = new Intent(_context, typeof(MainActivity));

            PendingIntent pendingIntent = PendingIntent.GetActivity(_context, NotificationId, intent, PendingIntentFlags.OneShot);

            // Add data to Bundle transfer object
            Bundle valuesForActivity = new Bundle();

            foreach (var item in data)
            {
                valuesForActivity.PutString(item.Key, item.Value);
            }

            intent.PutExtra(IntentDataKey, valuesForActivity);

            // When the user clicks the notification, MainActivity will start up and catche Intent
            Intent resultIntent = new Intent(_context, typeof(MainActivity));

            // Pass some values to started Activity:
            resultIntent.PutExtra(IntentDataKey, valuesForActivity);

            // Construct a back stack for cross-task navigation:
            Android.App.TaskStackBuilder stackBuilder = Android.App.TaskStackBuilder.Create(_context);
            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
            stackBuilder.AddNextIntent(resultIntent);

            // Create the PendingIntent with the back stack:
            PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, PendingIntentFlags.UpdateCurrent);

            // Build the notification:
            NotificationCompat.Builder builder = new NotificationCompat.Builder(_context)
                                                 .SetAutoCancel(true)                                           // Dismiss from the notif. area when clicked
                                                 .SetContentIntent(resultPendingIntent)                         // Start 2nd activity when the intent is clicked.
                                                 .SetContentTitle(title)                                        // Set its title
                                                 .SetNumber(4)                                                  // Display the count in the Content Info
                                                 .SetSmallIcon(Resource.Drawable.abc_ic_menu_overflow_material) // Display this icon
                                                 .SetContentText(body);                                         // The message to display.

            // Publish the notification:
            NotificationManager notificationManager = (NotificationManager)_context.GetSystemService(Context.NotificationService);

            notificationManager.Notify(NotificationId, builder.Build());
        }
コード例 #7
0
        void CreateNotification(PushNoticationMessage pushedMessage)
        {
            // Get the notifications manager:
            NotificationManager notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;

            // Instantiate the notification builder:
            Notification.Builder builder = new Notification.Builder(this)
                                           .SetContentTitle("WK Authenticator")
                                           .SetContentText(pushedMessage.Title)
                                           .SetAutoCancel(true)
                                           .SetSmallIcon(Resource.Drawable.icon)
                                           .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.icon));
            builder.SetVisibility(NotificationVisibility.Public);
            builder.SetPriority((int)NotificationPriority.High);
            builder.SetCategory(Notification.CategoryMessage);
            //Add Message Information to the Main Activity Intent - This will be shown on Tap Of the Notified Message
            Intent secondIntent = new Intent(this, typeof(MainActivity));

            // Pass the current notification string value to SecondActivity
            secondIntent.PutExtra("recdMessage", Common.Helpers.Settings.LastMessage);
            // Pressing the Back button in SecondActivity exits the app:
            Android.App.TaskStackBuilder stackBuilder = Android.App.TaskStackBuilder.Create(this);
            // Add the back stack for the intent:
            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
            // Push the intent (that starts SecondActivity) onto the stack. The
            // pending intent can be used only once (one shot):
            stackBuilder.AddNextIntent(secondIntent);
            const int     pendingIntentId = 0;
            PendingIntent pendingIntent   = stackBuilder.GetPendingIntent(pendingIntentId, PendingIntentFlags.OneShot);

            builder.SetContentIntent(pendingIntent);
            // Build the notification:
            Notification notification = builder.Build();

            notification.Defaults |= NotificationDefaults.Sound;
            // Notification ID used for all notifications in this app.
            // Reusing the notification ID prevents the creation of numerous different notifications as the user experiments with different notification settings -- each launch reuses
            // and updates the same notification.
            const int notificationId = 0;

            // Launch notification:
            notificationManager.Notify(notificationId, notification);
        }
コード例 #8
0
        void createNotification(string title, string desc, string confirmToken = null, string alertMessage = null)
        {
            //Create notification

            //Create an intent to show ui
            Intent uiIntent = new Intent(this, typeof(MainActivity));

            if (confirmToken != null && alertMessage != null)
            {
                uiIntent.PutExtra("confirmToken", confirmToken.ToString());
                uiIntent.PutExtra("alertMessage", alertMessage.ToString());
            }

            Android.App.TaskStackBuilder stackBuilder = Android.App.TaskStackBuilder.Create(this);

            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));

            stackBuilder.AddNextIntent(uiIntent);

            const int     pendingIntentId = 0;
            PendingIntent pendingIntent   =
                stackBuilder.GetPendingIntent(pendingIntentId, PendingIntentFlags.OneShot);

            Notification.Builder builder = new Notification.Builder(this)
                                           .SetContentIntent(pendingIntent)
                                           .SetContentTitle(title)
                                           .SetContentText(desc)
                                           .SetSmallIcon(Android.Resource.Drawable.SymActionEmail);

            // Build the notification:
            Notification notification = builder.Build();

            notification.Flags = NotificationFlags.AutoCancel;

            // Get the notification manager:
            NotificationManager notificationManager =
                GetSystemService(Context.NotificationService) as NotificationManager;

            // Publish the notification:
            const int notificationId = 0;

            notificationManager.Notify(notificationId, notification);
        }
コード例 #9
0
        public override void OnReceive(Context context, Intent intent)
        {
            Task.Run
            (
                async() =>
            {
                try
                {
                    // Wakelocker.Acquire(AppContext, WakelockTag);
                    // await new LocalOtaService().CacheAsync();
                    Logger.Debug("Notification OnReceive called");
                    int savedNotificationType = intent.GetIntExtra(NotificationType, 0);
                    if (savedNotificationType == 0)
                    {
                        Logger.Error("Unknown notification type");
                        return;
                    }
                    Logger.Debug("Notification type is " + savedNotificationType);
                    NotificationTypes notificationType = (NotificationTypes)savedNotificationType;
                    Logger.Debug("Showing notification of type " + notificationType.ToString());


                    if (notificationType == default(NotificationTypes))
                    {
                        return;
                    }



                    Logger.Debug("Booting up the core notification service");
                    NotificationsCoreService notificationsCoreService = new NotificationsCoreService();
                    Logger.Debug("Requesting core notification service for overdue notifications");
                    List <string> overdueNotifications =
                        await notificationsCoreService.GetOverdueNotificationsEntityIdsAsync(notificationType);

                    Logger.Debug("Establishing the notification helper to use");
                    NotificationsHelperBase notificationHelper = GetHelper(notificationType);

                    Logger.Debug("Asking notification helper to filter out notifications that aren't needed");
                    await notificationHelper.SetOverdueNotificationsAsync(overdueNotifications);

                    if (overdueNotifications == null)
                    {
                        overdueNotifications = new List <string>();
                    }
                    if (overdueNotifications.Count == 0)
                    {
                        Logger.Debug("Turns out there are no notifications to show");

                        return;
                    }


                    string message = notificationHelper.GetMessage();
                    PendingIntent contentIntent = PendingIntent.GetActivity(context, default(int), intent,
                                                                            PendingIntentFlags.CancelCurrent);



                    var notificationManager = NotificationManagerCompat.From(context);
                    var style = new NotificationCompat.BigTextStyle();
                    style.BigText(message);


                    var builder = new NotificationCompat.Builder(AppContext)
                                  .SetContentTitle(notificationHelper.GetTitle())
                                  .SetContentText(notificationHelper.GetMessage())
                                  .SetAutoCancel(notificationHelper.AutoCancel)
                                  .SetContentIntent(contentIntent)
                                  .SetSmallIcon(Resource.Drawable.Icon22x22)
                                  .SetStyle(style)
                                  .SetDefaults((int)notificationHelper.SoundAndOrVibrationAndOrLights)
                                  .SetWhen(JavaSystem.CurrentTimeMillis());

                    TaskStackBuilder taskStackBuilder = TaskStackBuilder.Create(AppContext);
                    Intent destIntent = await GetContentIntentAsync(notificationHelper, taskStackBuilder);

                    if (destIntent != null)
                    {
                        PendingIntent pendingIntent = taskStackBuilder.GetPendingIntent(0,
                                                                                        PendingIntentFlags.OneShot);
                        //PendingIntent.GetActivity(AppContext, 0, destIntent, PendingIntentFlags.OneShot);
                        builder.SetContentIntent(pendingIntent);
                    }
                    var notification = builder.Build();
                    notificationManager.Notify((int)notificationType, notification);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                    throw;
                }
                finally
                {
                    Wakelocker.Release();
                }
            }
            );
        }