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());
        }
        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());
        }
示例#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);
     }
 }
        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());
        }
        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);
        }
        private async Task <Intent> GetContentIntentAsync(NotificationsHelperBase notificationHelper, TaskStackBuilder taskStackBuilder)
        {
            bool loginExpired = !(await new LoginService().GetLoginValidityAsync());

            ISalesAppSession session = Resolver.Instance.Get <ISalesAppSession>();

            if (loginExpired || session == null || session.UserId == default(Guid))
            {
                return(new Intent(AppContext, typeof(LoginActivityView)));
            }
            else
            {
                Logger.Debug("Session id is " + session.UserId);
                DestinationInformation destinationInformation = notificationHelper.GetDestinationInformation();
                taskStackBuilder.AddParentStack(Class.FromType(destinationInformation.ActivityType));
                taskStackBuilder.AddNextIntent(destinationInformation.ContentIntent);
                return(destinationInformation.ContentIntent);
            }
        }
示例#9
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);
        }
示例#10
0
        //reads msgs from api every 3 sec
        private void getMsgs()
        {
            var thread = new Thread(async () =>
             {
                 MyMessage[] msgs;

                 Notification.Builder builder = new Notification.Builder(this)
                 .SetAutoCancel(true)
                 .SetSmallIcon(Resource.Drawable.notif)
                 .SetDefaults(NotificationDefaults.Sound);

                 var nMgr = (NotificationManager)GetSystemService(NotificationService);

                 Notification notification = new Notification(Resource.Drawable.notif, "message notification");

                 Intent intent = new Intent(this, typeof(ChatActivity));
                 PendingIntent pendingIntent;
                 ViewModel myViewModel = ViewModel.myViewModelInstance;

                 while (true)
                 {

                     string result = await ApiRequests.getMessages(MapActivity.client);
                     msgs = JsonConvert.DeserializeObject<MyMessage[]>(result);

                     if (notifCounter == 0)
                     {
                         for (int i = msgs.Length-1; i >=0; --i)
                         {
                             MyMessage msg = msgs[i];

                             if (!myViewModel.msgContainer.ContainsKey(msg.message_id))
                             {
                                 myViewModel.msgContainer.Add(msg.message_id, msg);
                                 myViewModel.msgsContainer.Add(msg);
                             }

                         }
                         notifCounter++;
                     }
                     else
                     {
                         for (int i = msgs.Length-1; i >= 0; --i)
                         {
                             MyMessage msg = msgs[i];
                             if (!myViewModel.msgContainer.ContainsKey(msg.message_id))
                             {

                                 myViewModel.msgContainer.Add(msg.message_id, msg);
                                 myViewModel.msgsContainer.Add(msg);

                                 if (msg.msg_type.Equals("from"))
                                 {
                                     intent.PutExtra("email", msg.email);
                                     intent.PutExtra("firstName", msg.first_name);
                                     intent.PutExtra("lastName", msg.last_name);

                                     stackBuilder = Android.App.TaskStackBuilder.Create(this);
                                     stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MapActivity)));
                                     stackBuilder.AddNextIntent(intent);

                                     pendingIntent = PendingIntent.GetActivity(this, notifCounter++, intent, PendingIntentFlags.OneShot);
                                     builder.SetContentIntent(pendingIntent);
                                     builder.SetContentTitle(msg.first_name + " " + msg.last_name);
                                     builder.SetContentText(msg.message);

                                     nMgr.Notify(notifCounter++, builder.Build());

                                     BroadcastStarted(msg);
                                 }
                             }
                         }

                     }
                     Thread.Sleep(3000);
                 }

             });

            thread.Start();
        }