コード例 #1
0
        private void UpdateNotification(bool firstNotification)
        {
            InitNotification();
            mNotificationBuilder.SetContentTitle(Resources.GetString(Resource.String.service_running));
            String secondLine = m_Network != null && m_Network.ClientConnected ?
                                String.Format(Resources.GetString(Resource.String.connected_with), m_Network.ClientName) :
                                Resources.GetString(Resource.String.not_connected);

            mNotificationBuilder.SetContentText(secondLine);
            var    style   = new Notification.BigTextStyle(mNotificationBuilder);
            String project = m_Project != null?
                             String.Format(Resources.GetString(Resource.String.loaded_project), m_Project.Title) :
                                 Resources.GetString(Resource.String.no_project);

            style.BigText(secondLine + "\n" + project);
            mNotificationBuilder.SetStyle(style);
            mNotificationBuilder.SetProgress(0, 0, false);
            if (firstNotification)
            {
                StartForeground(mNotificationId, mNotificationBuilder.Build());
            }
            else
            {
                var nMgr         = (NotificationManager)GetSystemService(NotificationService);
                var notification = mNotificationBuilder.Build();
                notification.Flags |= NotificationFlags.ForegroundService;
                nMgr.Notify(mNotificationId, notification);
            }
        }
コード例 #2
0
        private void Completed(object sender, AsyncCompletedEventArgs e)
        {
            timer.Stop();
            timer.Dispose();
            notificationManager.Cancel(notificationID);

            notificationID      = new System.Random().Next(10000, 99999);
            notificationBuilder = new Notification.Builder(ApplicationContext);
            notificationBuilder.SetOngoing(false)
            .SetSmallIcon(Resource.Drawable.icon);

            if (e.Cancelled == false && e.Error == null)
            {
                notificationBuilder.SetContentTitle("Download complete");
            }
            else
            {
                notificationBuilder.SetContentTitle("Upload failed");
            }

            notification = notificationBuilder.Build();
            notificationManager.Notify(notificationID, notification);

            notificationID = 0;

            notificationBuilder.Dispose();
            notification.Dispose();
            notificationManager.Dispose();

            uploadedBytes   = 0;
            totalBytes      = 0;
            percentComplete = 0;

            wClient.Dispose();
        }
コード例 #3
0
        /// <summary>
        /// Update the notification.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The updated notification.
        /// </returns>
        public Notification UpdateNotification(Context context)
        {
            var builder = new Notification.Builder(context);

            if (!string.IsNullOrEmpty(this.PausedText))
            {
                builder.SetContentTitle(this.PausedText);
                builder.SetContentText(string.Empty);
                builder.SetContentInfo(string.Empty);
            }
            else
            {
                builder.SetContentTitle(this.Title);
                if (this.TotalBytes > 0 && this.CurrentBytes != -1)
                {
                    builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false);
                }
                else
                {
                    builder.SetProgress(0, 0, true);
                }

                builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes));
                builder.SetContentInfo(string.Format("{0}s left", Helpers.GetTimeRemaining(this.TimeRemaining)));
            }

            builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload);
            builder.SetOngoing(true);
            builder.SetTicker(this.Ticker);
            builder.SetContentIntent(this.PendingIntent);

            return(builder.Notification);
        }
コード例 #4
0
        private void WClient_UploadFileCompleted(object sender, System.Net.UploadFileCompletedEventArgs e)
        {
            timer.Stop();
            timer.Dispose();

            notificationManager.Cancel(notificationID);

            notificationID      = new Random().Next(10000, 99999);
            notificationBuilder = new Notification.Builder(ApplicationContext);
            notificationBuilder.SetOngoing(false)
            .SetSmallIcon(Resource.Drawable.icon);

            if (e.Cancelled == false && e.Error == null)
            {
                JsonResult result = JsonConvert.DeserializeObject <JsonResult>(System.Text.Encoding.UTF8.GetString(e.Result));

                if (result != null && result.Success == true)
                {
                    notificationBuilder.SetContentTitle("Upload complete");
                }
                else
                if (result.Success == false)
                {
                    notificationBuilder.SetContentTitle("Upload failed");
                    Intent        notificationIntent = new Intent(ApplicationContext, typeof(UploadErrorActivity));
                    PendingIntent contentIntent      = PendingIntent.GetActivity(ApplicationContext,
                                                                                 0, notificationIntent, PendingIntentFlags.UpdateCurrent);
                    notificationBuilder.SetContentIntent(contentIntent);
                    notificationBuilder.SetContentText(result.Message);
                    notificationBuilder.SetAutoCancel(true);
                }
            }
            else
            {
                notificationBuilder.SetContentTitle("Upload failed");
            }

            notification = notificationBuilder.Build();
            notificationManager.Notify(notificationID, notification);

            notificationID = 0;

            notificationBuilder.Dispose();
            notification.Dispose();
            notificationManager.Dispose();

            uploadedBytes   = 0;
            totalBytes      = 0;
            percentComplete = 0;
            wClient.Dispose();
        }
コード例 #5
0
        public void OnIntentHandled(Message message)
        {
            Log.Info(MAIL_SERVICE_LOG_TAG, "OnIntentHandled");
            _intentCount--;

            if (_intentCount > 0)
            {
                var notification = _builder
                                   .SetContentTitle(string.Format(Resources.GetString(Resource.String.notification_text), _intentCount))
                                   .Build();

                NotificationManager.FromContext(this).Notify(SERVICE_RUNNING_NOTIFICATION_ID, notification);
            }
        }
コード例 #6
0
        protected void ShowNotification()
        {
            /*
            Notification.Builder builder = new Notification.Builder(this)
                .SetContentTitle("Break Time!")
                .SetContentText("You have passed a 3.5 hours and should take your 10 minute break if possible")
                .SetSmallIcon(Resource.Drawable.coffee);

            Notification notification = builder.Build();
            NotificationManager notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;

            const int notificationId = 0;
            notificationManager.Notify(notificationId, notification);
             *
             * */
            Notification notification;

            RemoteViews bigView = new RemoteViews(ApplicationContext.PackageName, Resource.Layout.notification_large);

            //PendingIntent testIntent = PendingIntent.GetActivities

            Notification.Builder builder = new Notification.Builder(this);
            notification = builder.SetContentTitle("Accrued Break Time")
                .SetContentText("You have reached a certain threshold to take a required break. Slide down for more details")
                .SetSmallIcon(Resource.Drawable.bussmall)
                .SetLargeIcon(Android.Graphics.BitmapFactory.DecodeResource(Resources, Resource.Drawable.bus))
                .Build();

            notification.BigContentView = bigView;

            NotificationManager manager = (NotificationManager)GetSystemService(Context.NotificationService) as NotificationManager;
            manager.Notify(0, notification);
        }
コード例 #7
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            view    = inflater.Inflate(Resource.Layout.Discussion_layout, container, false);
            builder = new Notification.Builder(this.Activity);
            builder.SetContentTitle("Submitted Ticket");

            disc_text     = view.FindViewById <EditText>(Resource.Id.discussion_text);
            disc_button   = view.FindViewById <Button>(Resource.Id.dsubmit);
            delete_button = view.FindViewById <Button>(Resource.Id.dsdelete);
            edit_button   = view.FindViewById <Button>(Resource.Id.dsput);
            recyclerView  = view.FindViewById <RecyclerView>(Resource.Id.recyclerView1);
            getdata();
            disc_button.Click += async delegate
            {
                postdata();
                notifier();
                getdata();
            };
            delete_button.Click += delegate
            {
                delete(index_id);
            };

            edit_button.Click += delegate
            {
                putdata(index_id);
            };
            return(view);
        }
コード例 #8
0
        private void Btn_edit_Click(object sender, EventArgs e)
        {
            if (notyBuilder == null)
            {
                Toast.MakeText(this, "هیچ نوتیفیکیشنی وجود ندارد", ToastLength.Short).Show();
            }
            else
            {
                notyBuilder.SetContentTitle("Updated Notification");
                notyBuilder.SetContentText("Changed to this message.");


                #region InboxStyle

                var inboxStyle = new Notification.InboxStyle();
                inboxStyle.AddLine("hamed: Bananas on sale");
                inboxStyle.AddLine("nili: Curious about your blog post");
                inboxStyle.AddLine("saeed: Need a ride to Evolve?");
                inboxStyle.SetSummaryText("+8 more");

                // Plug this style into the builder:
                notyBuilder.SetStyle(inboxStyle);

                #endregion
                var notification = notyBuilder.Build();
                var notyManager  = GetSystemService(Context.NotificationService) as NotificationManager;
                notyManager.Notify(notyId, notification);
            }
        }
コード例 #9
0
        public void ShowNotification(string title, string content)
        {
            CreatNotificationChannel();
            Context context     = Android.App.Application.Context;
            var     intent      = getLaucherActivity();
            var     stackBuiler = TaskStackBuilder.Create(context);

            stackBuiler.AddNextIntent(intent);
            var pendingIntent = stackBuiler.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            if (builder == null)
            {
                builder = new Notification.Builder(context, "channel_ID");
            }

            builder.SetAutoCancel(true);
            builder.SetContentTitle(title);
            builder.SetContentIntent(pendingIntent);
            builder.SetContentText(content);
            //

            builder.SetSmallIcon(Resource.Drawable.ic_vol_type_tv_dark);
            // Resource.Drawable.ic_stat_button_click;

            Notification notification = builder.Build();

            NotificationManager notificationManager =
                context.GetSystemService(Context.NotificationService) as NotificationManager;

            notificationManager.Notify(NOTIFICATION_ID, notification);
        }
コード例 #10
0
        public override void OnReceive(Context context, Intent intent)
        {
            using (var builder = new Notification.Builder(Application.Context))
            {
                builder.SetContentTitle(TranslationCodeExtension.GetTranslation("HalfWorkTitle"))
                .SetContentText(TranslationCodeExtension.GetTranslation("HalfWorkText"))
                .SetAutoCancel(true)
                .SetSmallIcon(Resource.Drawable.icon);

                var manager = (NotificationManager)Application.Context.GetSystemService(Context.NotificationService);

                if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
                {
                    var channelId = $"{Application.Context.PackageName}.general";
                    var channel   = new NotificationChannel(channelId, "General", NotificationImportance.Default);

                    manager.CreateNotificationChannel(channel);

                    builder.SetChannelId(channelId);
                }

                var resultIntent = GetLauncherActivity();
                resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
                var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(Application.Context);
                stackBuilder.AddNextIntent(resultIntent);
                var resultPendingIntent =
                    stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);
                builder.SetContentIntent(resultPendingIntent);

                manager.Notify(2, builder.Build());
                CrossVibrate.Current.Vibration(TimeSpan.FromMilliseconds(150));

                stackBuilder.Dispose();
            }
        }
コード例 #11
0
        private void HandleEnterZone(Zone z)
        {
            Log.Debug(TAG, "Enter zone " + z.Name);

            Intent notificationIntent = new Intent(this, typeof(NotificationActivity));

            notificationIntent.PutExtra("zone_id", z.Id);
            notificationIntent.PutExtra("zone_name", z.Name);
            notificationIntent.PutExtra("zone_color", z.Color);
            notificationIntent.PutExtra("zone_alias", z.Alias);

            PendingIntent pendingIntent = PendingIntent.GetActivity(
                this,
                z.Id,
                notificationIntent,
                PendingIntentFlags.UpdateCurrent);

            Notification.Builder notificationBuilder = new Notification.Builder(this);
            notificationBuilder.SetSmallIcon(Resource.Drawable.elm_logo);
            notificationBuilder.SetContentTitle("New zone");
            notificationBuilder.SetContentText("You have entered zone '" + z.Name + "'");
            notificationBuilder.SetDefaults(NotificationDefaults.Sound);
            notificationBuilder.SetAutoCancel(true);
            notificationBuilder.SetContentIntent(pendingIntent);

            // Get an instance of the NotificationManager service
            NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);

            //Build the notification and issues it with notification manager.
            notificationManager.Notify(z.Id, notificationBuilder.Build());
        }
コード例 #12
0
        private void InitBlockChain()
        {
            if (BlockChainService.BlockChain == null)
            {
                BlockChainService.BlockChain = new BlockChainVotings();

                BlockChainService.BlockChain.CheckRoot();

                Task.Run(() =>
                {
                    BlockChainService.BlockChain.Start();
                });

                BlockChainService.BlockChain.NewVoting += (s, a) =>
                {
                    RunOnUiThread(() =>
                    {
                        var notificationManager     = GetSystemService(NotificationService) as NotificationManager;
                        PendingIntent contentIntent = PendingIntent.GetActivity(this, 0, new Intent(this, typeof(MainActivity)), 0);

                        var builder = new Notification.Builder(this);
                        builder.SetAutoCancel(true);
                        builder.SetContentTitle(Resources.GetString(Resource.String.newVoting));
                        builder.SetContentText(BlockChainService.BlockChain.GetVotingName(a.Data));
                        builder.SetSmallIcon(Resource.Drawable.Icon);
                        builder.SetContentIntent(contentIntent);
                        var notification = builder.Build();

                        notificationManager.Notify(1, notification);
                    });
                };
            }
        }
コード例 #13
0
            public Notification Build(Builder b)
            {
                Notification.Builder builder = new Notification.Builder(b.Context);
                builder.SetContentTitle(b.ContentTitle)
                .SetContentText(b.ContentText)
                .SetTicker(b.Notification.TickerText)
                .SetSmallIcon(b.Notification.Icon, b.Notification.IconLevel)
                .SetContentIntent(b.ContentIntent)
                .SetDeleteIntent(b.Notification.DeleteIntent)
                .SetAutoCancel((b.Notification.Flags & NotificationFlags.AutoCancel) != 0)
                .SetLargeIcon(b.LargeIcon)
                .SetDefaults(b.Notification.Defaults);

                if (b.Style != null)
                {
                    if (b.Style is BigTextStyle)
                    {
                        BigTextStyle staticStyle        = b.Style as BigTextStyle;
                        Notification.BigTextStyle style = new Notification.BigTextStyle(builder);
                        style.SetBigContentTitle(staticStyle.BigContentTitle)
                        .BigText(staticStyle.bigText);
                        if (staticStyle.SummaryTextSet)
                        {
                            style.SetSummaryText(staticStyle.SummaryText);
                        }
                    }
                }

                return(builder.Build());
            }
コード例 #14
0
        /// <summary>
        /// Update the notification.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The updated notification.
        /// </returns>
        public Notification UpdateNotification(Context context)
        {
            if (builder == null)
            {
                builder = new Notification.Builder(context);
            }

            builder.SetContentTitle(this.Title);
            if (this.TotalBytes > 0 && this.CurrentBytes != -1)
            {
                builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false);
            }
            else
            {
                builder.SetProgress(0, 0, true);
            }
            builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes));
            builder.SetContentInfo(context.GetString(Resource.String.time_remaining_notification, Helpers.GetTimeRemaining(this.TimeRemaining)));
            builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload);
            builder.SetOngoing(true);
            builder.SetTicker(this.Ticker);
            builder.SetContentIntent(this.PendingIntent);

            return(builder.Notification);
        }
        /// <summary>
        /// Update the notification.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The updated notification.
        /// </returns>
        public Notification UpdateNotification(Context context)
        {
            var builder = new Notification.Builder(context);
            if (!string.IsNullOrEmpty(this.PausedText))
            {
                builder.SetContentTitle(this.PausedText);
                builder.SetContentText(string.Empty);
                builder.SetContentInfo(string.Empty);
            }
            else
            {
                builder.SetContentTitle(this.Title);
                if (this.TotalBytes > 0 && this.CurrentBytes != -1)
                {
                    builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false);
                }
                else
                {
                    builder.SetProgress(0, 0, true);
                }

                builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes));
                builder.SetContentInfo(string.Format("{0}s left", Helpers.GetTimeRemaining(this.TimeRemaining)));
            }

            builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload);
            builder.SetOngoing(true);
            builder.SetTicker(this.Ticker);
            builder.SetContentIntent(this.PendingIntent);

            return builder.Notification;
        }
コード例 #16
0
        private void InitFragment()
        {
            mConversationFragment = (ConversationFragment)SupportFragmentManager.FindFragmentByTag(LivepersonFragment);
            Log.Debug(Tag, "initFragment. mConversationFragment = " + mConversationFragment);

            try
            {
                if (mConversationFragment == null)
                {
                    /*
                     *
                     * String authCode = SampleAppStorage.getInstance(FragmentContainerActivity.this).getAuthCode();
                     * String publicKey = SampleAppStorage.getInstance(FragmentContainerActivity.this).getPublicKey();
                     *
                     * Log.d(TAG, "initFragment. authCode = "+ authCode);
                     * Log.d(TAG, "initFragment. publicKey = "+ publicKey);
                     * LPAuthenticationParams authParams = new LPAuthenticationParams();
                     * authParams.setAuthKey(authCode);
                     * authParams.addCertificatePinningKey(publicKey);
                     */
                    LPAuthenticationParams authParams             = new LPAuthenticationParams();
                    CampaignInfo           campaignInfo           = null;//SampleAppUtils.getCampaignInfo(this);
                    ConversationViewParams conversationViewParams = new ConversationViewParams().SetCampaignInfo(campaignInfo).SetReadOnlyMode(isReadOnly());
                    mConversationFragment = (ConversationFragment)LivePerson.GetConversationFragment(authParams, conversationViewParams);

                    if (isValidState())
                    {
                        // Pending intent for image foreground service
                        Intent notificationIntent = new Intent(CallBackInFragmentcontext, typeof(Activity_Message));
                        //notificationIntent.SetFlags(Intent.Flags);
                        PendingIntent pendingIntent = PendingIntent.GetActivity(CallBackInFragmentcontext, 0, notificationIntent, 0);
                        LivePerson.SetImageServicePendingIntent(pendingIntent);

                        // Notification builder for image upload foreground service
                        Notification.Builder uploadBuilder   = new Notification.Builder(CallBackInFragmentcontext);
                        Notification.Builder downloadBuilder = new Notification.Builder(CallBackInFragmentcontext);
                        uploadBuilder.SetContentTitle("Uploading image")
                        //.SetSmallIcon(Android.R.drawable.arrow_up_float)
                        .SetContentIntent(pendingIntent)
                        .SetProgress(0, 0, true);

                        downloadBuilder.SetContentTitle("Downloading image")
                        //.setSmallIcon(Android.R.drawable.arrow_down_float)
                        .SetContentIntent(pendingIntent)
                        .SetProgress(0, 0, true);

                        LivePerson.SetImageServiceUploadNotificationBuilder(uploadBuilder);
                        LivePerson.SetImageServiceDownloadNotificationBuilder(downloadBuilder);

                        var ft = SupportFragmentManager.BeginTransaction();
                        ft.Add(Resource.Id.frameLayout1, mConversationFragment, LivepersonFragment).CommitAllowingStateLoss();
                    }
                }
                else
                {
                    AttachFragment();
                }
            }
            catch (Java.Lang.Exception e) { throw e; }
        }
コード例 #17
0
        void CreateNotification()
        {
            NotificationManager manager = Android.App.Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;
            var builder = new Notification.Builder(Android.App.Application.Context);

            builder.SetContentTitle("Test Notification");
            builder.SetContentText("This is the body");
            builder.SetAutoCancel(true);
            builder.SetSmallIcon(Resource.Drawable.clipboard);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var channelId = "com.companyname.briefing.general";
                var channel   = new NotificationChannel(channelId, "General", NotificationImportance.Default);

                manager.CreateNotificationChannel(channel);

                builder.SetChannelId(channelId);
            }
            var resultIntent = Android.App.Application.Context.PackageManager.GetLaunchIntentForPackage(Android.App.Application.Context.PackageName);

            resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
            var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(Android.App.Application.Context);

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

            builder.SetContentIntent(resultPendingIntent);

            manager.Notify(0, builder.Build());
        }
コード例 #18
0
        protected override void OnMessage(Context context, Intent intent)
        {
            string message = string.Empty;

            // Extract the push notification message from the intent.
            if (intent.Extras.ContainsKey("message"))
            {
                message = intent.Extras.Get("message").ToString();
                var title = "Doctor Notification";

                // Create a notification manager to send the notification.
                var notificationManager =
                    GetSystemService(NotificationService) as NotificationManager;

                // Create a new intent to show the notification in the UI.
                PendingIntent contentIntent =
                    PendingIntent.GetActivity(context, 0,
                                              new Intent(this, typeof(MainActivity)), 0);

                // Create the notification using the builder.
                var builder = new Notification.Builder(context);
                builder.SetAutoCancel(true);
                builder.SetContentTitle(title);
                builder.SetContentText(message);
                builder.SetSmallIcon(Resource.Drawable.ic_launcher);
                builder.SetContentIntent(contentIntent);
                var notification = builder.Build();

                // Display the notification in the Notifications Area.
                notificationManager.Notify(1, notification);

                ShowPopUp(context, message);
            }
        }
コード例 #19
0
        public override void OnReceive(Context context, Intent intent)
        {
            string profileName = intent.Categories.ToArray()[0];

            ProfileManager profileMgr = new ProfileManager();
            Profile        prof       = profileMgr.GetProfile(profileName);

            if (prof == null || !prof.Active)
            {
                return;
            }

            prof.Allowed = true;
            Scheduler scheduler = new Scheduler();

            scheduler.ScheduleNextDisable(prof);

            profileMgr.SaveProfile(prof);

            Notification.Builder builder = new Notification.Builder(Application.Context);
            builder/*.SetSmallIcon(???)*/
            .SetContentTitle(profileName)
            .SetContentText("Anufe sind jetzt erlaubt.");
            Notification        noti    = builder.Build();
            NotificationManager notiMgr = (NotificationManager)Application.Context.GetSystemService(Context.NotificationService);

            notiMgr?.Notify(profileName.GetHashCode(), noti);
        }
コード例 #20
0
        protected override void OnMessage(Context context, Intent intent)
        {
            var currentActivity = Mvx.Resolve <IMvxAndroidCurrentTopActivity>().Activity;
            var message         = string.Empty;

            // Extract the push notification message from the intent.
            if (intent.Extras.ContainsKey("message"))
            {
                message = intent.Extras.Get("message").ToString();
                var title = "New item added:";

                // Create a notification manager to send the notification.
                var notificationManager =
                    GetSystemService(NotificationService) as NotificationManager;

                // Create a new intent to show the notification in the UI.
                var contentIntent =
                    PendingIntent.GetActivity(context, 0,
                                              new Intent(this, currentActivity.GetType()), 0);

                // Create the notification using the builder.
                var builder = new Notification.Builder(context);
                builder.SetAutoCancel(true);
                builder.SetContentTitle(title);
                builder.SetContentText(message);
                builder.SetSmallIcon(Resource.Drawable.ic_launcher);
                builder.SetContentIntent(contentIntent);
                var notification = builder.Build();

                // Display the notification in the Notifications Area.
                notificationManager.Notify(1, notification);
            }
        }
        //internal static bool
        void HandleNotification(string messageBody, string messageTitle)
        {
            var intent = new Intent(Forms.Context, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
            var pendingIntent = PendingIntent.GetActivity(Forms.Context, 0, intent, PendingIntentFlags.UpdateCurrent);


            var n = new Notification.Builder(Forms.Context);

            n.SetSmallIcon(Resource.Drawable.notification_template_icon_bg);
            n.SetLights(Android.Graphics.Color.Blue, 300, 1000);
            n.SetContentIntent(pendingIntent);
            n.SetContentTitle(messageTitle);
            n.SetTicker(messageBody);
            //n.SetLargeIcon(global::Android.Graphics.BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.icon));
            n.SetAutoCancel(true);
            n.SetContentText(messageBody);
            n.SetVibrate(new long[] {
                200,
                200,
                100,
            });

            var nm = NotificationManager.FromContext(Forms.Context);

            nm.Notify(0, n.Build());

            // Make call to Xamarin.Forms here with the event handler
        }
コード例 #22
0
        public void ShowNotification(Intent intent)
        {
            var id    = intent.GetIntExtra("id", 0);
            var title = intent.GetStringExtra("title");
            var body  = intent.GetStringExtra("message");

            var main_intent = new Intent(this, typeof(MainActivity));

            main_intent.PutExtra("type", "alarm");
            main_intent.PutExtra("id", id);

            var builder = new Notification.Builder(this);

            //builder.SetGroup("keep.grass");
            builder.SetTicker(title);
            builder.SetContentTitle(title);
            builder.SetContentText(body);
            builder.SetContentIntent
            (
                PendingIntent.GetActivity
                (
                    this,
                    id,
                    main_intent,
                    PendingIntentFlags.UpdateCurrent
                )
            );
            builder.SetSmallIcon(Resource.Drawable.icon);
            builder.SetLargeIcon(BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.icon));
            builder.SetDefaults(NotificationDefaults.All);
            builder.SetAutoCancel(true);

            ((NotificationManager)this.GetSystemService(NotificationService))
            .Notify(id, builder.Build());
        }
コード例 #23
0
        private void ExibirInboxNotificacao()
        {
            Notification.Builder builder = new Notification.Builder(this)
                .SetContentTitle ("Sample Notification")
                .SetContentText ("Hello World! This is my first action notification!")
                .SetDefaults (NotificationDefaults.Sound)
                .SetSmallIcon (Resource.Drawable.Icon);

            // Instantiate the Inbox style:
            Notification.InboxStyle inboxStyle = new Notification.InboxStyle();

            // Set the title and text of the notification:
            builder.SetContentTitle ("5 new messages");
            builder.SetContentText ("*****@*****.**");

            // Generate a message summary for the body of the notification:
            inboxStyle.AddLine ("Cheeta: Bananas on sale");
            inboxStyle.AddLine ("George: Curious about your blog post");
            inboxStyle.AddLine ("Nikko: Need a ride to Evolve?");
            inboxStyle.SetSummaryText ("+2 more");

            // Plug this style into the builder:
            builder.SetStyle (inboxStyle);

            Notification notification = builder.Build();

            NotificationManager notificationManager =
                GetSystemService (Context.NotificationService) as NotificationManager;

            const int notificationId = 0;
            notificationManager.Notify (notificationId, notification);
        }
コード例 #24
0
        public async void Validate(string device, string correo, string contrasena)
        {
            string Result;
            var    ValidationResultTextView = FindViewById <TextView>(Resource.Id.ValidationResultTextView);
            var    Builder       = new Notification.Builder(this);
            var    ServiceClient = new SALLab07.ServiceClient();

            Console.WriteLine($"{correo} | {contrasena}");
            var SvcResult = await ServiceClient.ValidateAsync(
                correo,
                contrasena,
                device);

            Result = $"{SvcResult.Status}\n{SvcResult.Fullname}\n{SvcResult.Token}";

            if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                Builder.SetContentTitle("Resultado de la Validación");
                Builder.SetContentText(Result);
                Builder.SetSmallIcon(Resource.Drawable.Icon);
                Builder.SetCategory(Notification.CategoryMessage);

                var ObjectNotification = Builder.Build();
                var Manager            = GetSystemService(
                    Android.Content.Context.NotificationService) as NotificationManager;
                Manager.Notify(0, ObjectNotification);
            }
            else
            {
                ValidationResultTextView.Text = Result;
            }
        }
コード例 #25
0
        protected override void OnMessage(Context context, Intent intent)
        {

            string message = string.Empty;

            // Extract the push notification message from the intent.
            if (intent.Extras.ContainsKey("message"))
            {
                message = intent.Extras.Get("message").ToString();
                var title = "Doctor Notification";

                // Create a notification manager to send the notification.
                var notificationManager =
                    GetSystemService(NotificationService) as NotificationManager;

                // Create a new intent to show the notification in the UI. 
                PendingIntent contentIntent =
                    PendingIntent.GetActivity(context, 0,
                    new Intent(this, typeof(MainActivity)), 0);

                // Create the notification using the builder.
                var builder = new Notification.Builder(context);
                builder.SetAutoCancel(true);
                builder.SetContentTitle(title);
                builder.SetContentText(message);
                builder.SetSmallIcon(Resource.Drawable.ic_launcher);
                builder.SetContentIntent(contentIntent);
                var notification = builder.Build();

                // Display the notification in the Notifications Area.
                notificationManager.Notify(1, notification);

                ShowPopUp(context, message);
            }
        }
コード例 #26
0
ファイル: Gcm.cs プロジェクト: jv9/Techorama-2014
        protected override void OnMessage(Context context, Intent intent)
        {
            Console.WriteLine("Received Notification");

            //Push Notification arrived - print out the keys/values
            if (intent != null || intent.Extras != null)
            {
                var keyset = intent.Extras.KeySet();

                foreach (var key in intent.Extras.KeySet())
                {
                    Console.WriteLine("Key: {0}, Value: {1}", key, intent.Extras.GetString(key));
                }

                var msg = intent.GetStringExtra("message");

                var n = new Notification.Builder(context);
                n.SetSmallIcon(Android.Resource.Drawable.IcDialogAlert);
                n.SetContentTitle("InFridge Expiration Notice");
                n.SetTicker(msg);
                n.SetContentText(msg);

                var nm = NotificationManager.FromContext(context);
                nm.Notify(0, n.Build());
            }
        }
コード例 #27
0
        public override void OnReceive(Context context, Intent intent)
        {
            //
            var notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);

            //
            var resultIntent = new Intent(context, typeof(AfazerService));

            /*TaskStackBuilder stackBuilder = TaskStackBuilder.Create(context);
             * stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(AfazerService)));
             * stackBuilder.AddNextIntent(resultIntent);*/

            //
            //PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, PendingIntentFlags.UpdateCurrent);
            //
            var builder = new Notification.Builder(context);

            builder.SetAutoCancel(true);
            //builder.SetContentIntent(resultPendingIntent);
            builder.SetContentTitle(_title);
            builder.SetContentText(_description);
            builder.SetDefaults(NotificationDefaults.All);
            builder.SetSmallIcon(Resource.Drawable.icon);

            //
            notificationManager.Notify(100, builder.Build());
        }
コード例 #28
0
      public Notification Build(Builder b) {
        Notification.Builder builder = new Notification.Builder(b.Context);
        builder.SetContentTitle(b.ContentTitle)
          .SetContentText(b.ContentText)
          .SetTicker(b.Notification.TickerText)
          .SetSmallIcon(b.Notification.Icon, b.Notification.IconLevel)
          .SetContentIntent(b.ContentIntent)
          .SetDeleteIntent(b.Notification.DeleteIntent)
          .SetAutoCancel((b.Notification.Flags & NotificationFlags.AutoCancel) != 0)
          .SetLargeIcon(b.LargeIcon)
          .SetDefaults(b.Notification.Defaults);

        if (b.Style != null) {
          if (b.Style is BigTextStyle) {
            BigTextStyle staticStyle = b.Style as BigTextStyle;
            Notification.BigTextStyle style = new Notification.BigTextStyle(builder);
            style.SetBigContentTitle(staticStyle.BigContentTitle)
              .BigText(staticStyle.bigText);
            if (staticStyle.SummaryTextSet) {
              style.SetSummaryText(staticStyle.SummaryText);
            }
          }
        }

        return builder.Build();
      }
コード例 #29
0
        public Notification GetNotification(NotificationManager notificationManager, Reminder reminder, Context context)
        {
            var    importance   = NotificationImportance.High;
            string channel_id   = context.GetString(Resource.String.notification_channel_id);
            string channel_name = context.GetString(Resource.String.notification_channel_name);

            NotificationChannel channel = new NotificationChannel(channel_id, channel_name, importance);

            channel.EnableVibration(true);
            channel.EnableLights(true);
            channel.LockscreenVisibility = NotificationVisibility.Public;

            notificationManager.CreateNotificationChannel(channel);

            // Instantiate the builder and set notification elements
            Notification.Builder builder = new Notification.Builder(context, channel_id);

            builder
            .SetContentTitle(reminder.Title)
            .SetContentText(reminder.Comment)
            .SetContentIntent(GetRemindersListPendingIntent(context))
            .SetAutoCancel(true)
            .SetTicker($"{reminder.Title} {reminder.Comment}")
            .SetSmallIcon(Resource.Drawable.notification_icon);

            // Build the notification
            return(builder.Build());
        }
コード例 #30
0
        public static void BuildNotification(String songId)
        {
            MediaMetadataRetriever metadata = SongMetadata.GetMetadata(songId);

            string title   = metadata.ExtractMetadata(MetadataKey.Title);
            string content = metadata.ExtractMetadata(MetadataKey.Artist);

            if (title == null || content == null)
            {
                title   = "TubeLoad";
                content = AndroidSongsManager.Instance.GetSong(songId).Name.Replace(".mp3", "");
            }

            builder.SetSmallIcon(Resource.Drawable.icon);
            Drawable drawable = SongMetadata.GetSongPicture(songId);
            Bitmap   bitmap;

            if (drawable != null)
            {
                bitmap = ((BitmapDrawable)SongMetadata.GetSongPicture(songId)).Bitmap;
            }
            else
            {
                bitmap = BitmapFactory.DecodeResource(Application.Context.Resources, Resource.Drawable.default_song_image);
            }

            if (Android.OS.Build.VERSION.SdkInt > Android.OS.BuildVersionCodes.M)
            {
                RemoteViews notificationLayoutExpanded = new RemoteViews(Application.Context.PackageName, Resource.Layout.view_notification_actions);
                notificationLayoutExpanded.SetTextViewText(Resource.Id.notificationTitle, title);
                notificationLayoutExpanded.SetTextViewText(Resource.Id.notificationContent, content);
                notificationLayoutExpanded.SetImageViewBitmap(Resource.Id.songImg, bitmap);
                CreateNotificationMediaActions(notificationLayoutExpanded);
                builder.SetCustomBigContentView(notificationLayoutExpanded);
                builder.SetContentTitle(title);
            }
            else
            {
                builder.SetLargeIcon(bitmap);
                builder.SetContentTitle(title);
                builder.SetContentText(content);
            }

            songNotification = builder.Build();

            notificationManager.Notify(SONG_NOTIFICATION_ID, songNotification);
        }
コード例 #31
0
        public void checkchange()
        {
            while (true)
            {
                IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
                foreach (IPAddress ip in localIPs)
                {
                    if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        if (ipadre != ip.ToString())
                        {
                            servidor.Stop();
                            ipadre = ip.ToString();



                            servidor = new MultitubeWebServer(Android.OS.Environment.ExternalStorageDirectory.ToString(), 12345, ipadre, this);
                            var brandom = new Random();

                            Intent internado2                 = new Intent(this, typeof(serviciointerpreter23));
                            Intent internado3                 = new Intent(this, typeof(serviciointerpreter234));
                            var    pendingIntent3             = PendingIntent.GetService(ApplicationContext, brandom.Next(2000, 50000) + brandom.Next(2000, 50000), internado3, 0);
                            var    pendingIntent2             = PendingIntent.GetService(ApplicationContext, brandom.Next(2000, 50000) + brandom.Next(2000, 50000), internado2, 0);
                            Notification.Action       accion  = new Notification.Action(Resource.Drawable.drwaable, "Parar", pendingIntent2);
                            Notification.Action       accion2 = new Notification.Action(Resource.Drawable.drwaable, "Conectarse", pendingIntent3);
                            Notification.BigTextStyle textoo  = new Notification.BigTextStyle();
                            textoo.SetBigContentTitle("Stremeando en " + ipadre + ":12345");
                            textoo.SetSummaryText("Toque para parar de stremear su media");
                            textoo.BigText("Para conectarse introduzca " + ipadre + ":12345  " + "en su navegador o entre a multitubeweb.tk y toque conectar luego escanee el codigo que aparece al presionar el boton de + en multitubeweb.   al tocar parar se cierrar el servicio de streaming");


#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
                            Notification.Builder nBuilder = new Notification.Builder(this);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos
                            nBuilder.SetContentTitle("Stremeando en " + ipadre + ":12345");
                            nBuilder.SetContentText("Toque para parar de stremear su media");
                            nBuilder.SetStyle(textoo);
                            nBuilder.SetColor(Android.Graphics.Color.DarkRed.ToArgb());
                            nBuilder.SetOngoing(true);
                            //   nBuilder.SetContentIntent(pendingIntent2);
                            nBuilder.SetSmallIcon(Resource.Drawable.antena);
                            nBuilder.AddAction(accion);
                            nBuilder.AddAction(accion2);
                            Notification notification = nBuilder.Build();
                            StartForeground(193423456, notification);



                            if (CheckInternetConnection() && Constants.UseFirebase)
                            {
                                meterdata();
                            }
                        }
                    }
                }
                MultiHelper.ExecuteGarbageCollection();
                Thread.Sleep(5000);
            }
        }
コード例 #32
0
        private void Button_Click(object sender, EventArgs e)
        {
            notyBuilder = new Notification.Builder(this);

            notyBuilder.SetContentTitle("عنوان پیام");
            notyBuilder.SetContentText("متن پیام در اینجا قرار میگیرد");
            notyBuilder.SetSmallIcon(Resource.Drawable.noty_small_icon);
            notyBuilder.SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.noty_large_icon));
            notyBuilder.SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis());
            notyBuilder.SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate);
            notyBuilder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));
            notyBuilder.SetAutoCancel(true);
            notyBuilder.SetPriority((int)NotificationPriority.High);

            if ((int)Android.OS.Build.VERSION.SdkInt >= 21)
            {
                notyBuilder.SetVisibility(NotificationVisibility.Public);
                notyBuilder.SetCategory(Notification.CategoryEmail);
            }



            #region BigTextStyle

            Notification.BigTextStyle textStyle = new Notification.BigTextStyle();
            string longTextMessage = "I went up one pair of stairs.";
            longTextMessage += " / Just like me. ";
            textStyle.BigText(longTextMessage);
            textStyle.SetSummaryText("The summary text goes here.");
            //notyBuilder.SetStyle(textStyle);

            #endregion

            #region InboxStyle

            var inboxStyle = new Notification.InboxStyle();
            inboxStyle.AddLine("Cheeta: Bananas on sale");
            inboxStyle.AddLine("George: Curious about your blog post");
            inboxStyle.AddLine("Nikko: Need a ride to Evolve?");
            inboxStyle.SetSummaryText("+2 more");

            notyBuilder.SetStyle(inboxStyle);

            #endregion

            #region imageStyle

            var imageStyle = new Notification.BigPictureStyle();
            imageStyle.BigPicture(BitmapFactory.DecodeResource(Resources, Resource.Drawable.facebook));
            imageStyle.SetSummaryText("+2 more");
            //notyBuilder.SetStyle(imageStyle);


            #endregion

            var notification = notyBuilder.Build();
            var notyManager  = GetSystemService(Context.NotificationService) as NotificationManager;
            notyManager.Notify(notyId, notification);
        }
コード例 #33
0
 public override void OnCreate()
 {
     Notification.Builder builder = new Notification.Builder(ApplicationContext);
     builder.SetContentTitle("DSAMobile");
     builder.SetContentText("DSAMobile service is running");
     builder.SetOngoing(true);
     _serviceNotification = builder.Build();
 }
コード例 #34
0
        public void SentNoficationForNewInovoice(List <Customer> countNewНotifyNewInvoiceCustomers)
        {
            if (countNewНotifyNewInvoiceCustomers.Count > 0)
            {
                // Set up an intent so that tapping the notifications returns to this app:
                Intent intent = new Intent(this, typeof(MainActivity));

                // Create a PendingIntent;
                const int     pendingIntentId = 1;
                PendingIntent pendingIntent   =
                    PendingIntent.GetActivity(this, pendingIntentId, intent, PendingIntentFlags.OneShot);


                // Instantiate the Inbox style:
                Notification.InboxStyle inboxStyle = new Notification.InboxStyle();

                //  Instantiate the builder and set notification elements:
                Notification.Builder bulideer = new Notification.Builder(this);

                bulideer.SetContentIntent(pendingIntent);
                bulideer.SetSmallIcon(Resource.Drawable.vik);

                // Set the title and text of the notification:
                bulideer.SetContentTitle("Нова фактура");
                //  bulideer.SetContentText("*****@*****.**");

                foreach (var item in countNewНotifyNewInvoiceCustomers)
                {
                    // Generate a message summary for the body of the notification:

                    //  if(item.DidGetNewInoviceToday == false)
                    //  {
                    string money = item.MoneyToPay.ToString("C", System.Globalization.CultureInfo.GetCultureInfo("bg-BG"));

                    inboxStyle.AddLine($"Аб. номер: {item.Nomer.ToString()}, {money}");

                    bulideer.SetContentText($"Аб. номер: {item.Nomer.ToString()}, {money}");

                    // item.DidGetNewInoviceToday = true;
                    //  }
                }
                // Plug this style into the builder:
                bulideer.SetStyle(inboxStyle);

                // Build the notification:
                Notification notification11 = bulideer.Build();

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

                // Publish the notification:
                const int notificationIdd = 1;
                notificationManager1.Notify(notificationIdd, notification11);
            }
        }
コード例 #35
0
        public void CreateSimplestNotification()
        {
            CreateNotificationChannel();
            var builder = new Notification.Builder(_lastChannelId);

            builder.SetContentTitle("Simple");
            builder.SetContentText("Notification");
            builder.SetSmallIcon("notify_icon_small");
            Notify(builder);
        }
コード例 #36
0
        /// <summary>
        /// Show a local notification in the Notification Area and Drawer.
        /// </summary>
        /// <param name="title">Title of the notification</param>
        /// <param name="body">Body or description of the notification</param>
        public void Show(string title, string body)
        {
            var builder = new Notification.Builder(Application.Context);
            builder.SetContentTitle(title);
            builder.SetContentText(body);
            builder.SetSmallIcon(Resource.Drawable.Icon);

            var notification = builder.Build();

            var manager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;

            manager.Notify(0, notification);
        }
コード例 #37
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            txtView = (TextView)FindViewById(Resource.Id.tbNotificationInfo);
            //txtView = (TextView)FindViewById(Resource.Id.textView1);
            nReceiver = new NotificationReceiver();
            IntentFilter filter = new IntentFilter();
            filter.AddAction("com.dpwebdev.handsetfree.NOTIFICATION_LISTENER_EXAMPLE");
            RegisterReceiver(nReceiver, filter);

            // Get our button from the layout resource,
            // and attach an event to it
            Button createButton = FindViewById<Button>(Resource.Id.MyButton);
            Button catchButton = FindViewById<Button>(Resource.Id.catchNotification);

            createButton.Click += delegate
            {
                NotificationManager nManager = (NotificationManager)GetSystemService(NotificationListenerService.NotificationService);
                Notification.Builder ncomp = new Notification.Builder(this);
                ncomp.SetContentTitle("My Notification");
                ncomp.SetContentText("Notification Listener Service Example");
                ncomp.SetTicker("Notification Listener Service Example");
                ncomp.SetSmallIcon(Resource.Drawable.Icon);
                ncomp.SetAutoCancel(true);
                nManager.Notify(DateTime.Now.Millisecond, ncomp.Build());

                

            };

            catchButton.Click += delegate
            {
                
                Intent i = new Intent("com.dpwebdev.handsetfree.NOTIFICATION_LISTENER_SERVICE_EXAMPLE");
                i.PutExtra("command", "list");
                SendBroadcast(i);
            };

        }
コード例 #38
0
ファイル: GcmListenerService.cs プロジェクト: frungillo/cim
        void SendNotification(MessaggioNotifica m)
        {
            var intent = new Intent (this, typeof(MainActivity));

            intent.AddFlags (ActivityFlags.ClearTop);

            var notifica = new Notification.Builder (this);
            switch (m.Tipo) {
            case "1":
                notifica.SetSmallIcon (Resource.Drawable.alert_1);
                break;
            case "2":
                notifica.SetSmallIcon (Resource.Drawable.alert_2);
                break;
            case "3":
                notifica.SetSmallIcon (Resource.Drawable.alert_3);
                break;
            default:
                notifica.SetSmallIcon (Resource.Drawable.InvioDoc);
                break;
            }

            if (m.Tipo == "4") {
                Messaggio mess = new Messaggio (m.Titolo, m.Messaggio);
                intent.PutExtra ("messaggio", JsonConvert.SerializeObject(mess));
            } else {
                intent.PutExtra ("commessanum", m.Commessa);
            }
            var pendingIntent = PendingIntent.GetActivity (this, 0, intent, PendingIntentFlags.OneShot);

            notifica.SetContentTitle (m.Titolo);
            notifica.SetContentText (m.Messaggio);
            notifica.SetAutoCancel (true);
            notifica.SetContentInfo (m.Commessa);
            notifica.SetSubText ("Commessa " + m.Commessa);
            notifica.SetVibrate (new long[] {100,200,100});
            notifica.SetSound (RingtoneManager.GetDefaultUri(RingtoneType.Notification));
            notifica.SetContentIntent (pendingIntent);
            var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
            notificationManager.Notify (0, notifica.Build());
        }
コード例 #39
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();
        }
コード例 #40
0
ファイル: WakeUpService.cs プロジェクト: eardic/ScreenWaker
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            base.OnStartCommand(intent, flags, startId);

            var notificationIntent = new Intent(BaseContext, typeof(MainActivity));
            notificationIntent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
            var notifPendingIntent = PendingIntent.GetActivity(BaseContext, 0, notificationIntent, PendingIntentFlags.UpdateCurrent);
            var notif = new Notification
            {
                ContentIntent = notifPendingIntent
            };

            Notification.Builder notifBuilder = new Notification.Builder(BaseContext);
            notifBuilder.SetContentIntent(notifPendingIntent);
            notifBuilder.SetWhen(JavaSystem.CurrentTimeMillis());
            notifBuilder.SetSmallIcon(Resource.Drawable.Knock);
            notifBuilder.SetContentTitle(Resources.GetString(Resource.String.ApplicationName));
            notifBuilder.SetContentText(Resources.GetString(Resource.String.NotifText));

            StartForeground(Process.MyPid(), notifBuilder.Build());
            
            //var notificationManager = (NotificationManager) BaseContext.GetSystemService(NotificationService);
            //notificationManager.Notify(Process.MyPid(), new Notification { ContentIntent = notifPendingIntent });

            RegisterListener();

            _wakeLockPartial?.Acquire();

            Status = ServiceStatus.STARTED;
            Log.Debug("WakeUpService", "Service start command.");
            return StartCommandResult.StickyCompatibility;
        }
コード例 #41
0
ファイル: PlayerService.cs プロジェクト: puncsky/DrunkAudible
        /// <summary>
        /// When we start on the foreground we will present a notification to the user
        /// When they press the notification it will take them to the main page so they can control the music
        /// </summary>
        void StartForeground ()
        {
            var intent = new Intent (ApplicationContext, typeof (MainActivity));
            intent.SetAction (Intent.ActionMain);
            intent.AddCategory (Intent.CategoryLauncher);
            ExtraUtils.PutSelectedTab (intent, (int) MainActivity.TabTitle.Player);

            var pendingIntent = PendingIntent.GetActivity (
                ApplicationContext,
                0,
                intent,
                PendingIntentFlags.UpdateCurrent
            );

            var notificationBuilder = new Notification.Builder (ApplicationContext);
            notificationBuilder.SetContentTitle (CurrentEpisode.Title);
            notificationBuilder.SetContentText (
                String.Format (
                    ApplicationContext.GetString (Resource.String.NotificationContentText),
                    ApplicationContext.GetString (Resource.String.ApplicationName)
                )
            );
            notificationBuilder.SetSmallIcon (Resource.Drawable.ic_stat_av_play_over_video);
            notificationBuilder.SetTicker (
                String.Format (
                    Application.GetString (Resource.String.NoticifationTicker),
                    CurrentEpisode.Title
                )
            );
            notificationBuilder.SetOngoing (true);
            notificationBuilder.SetContentIntent (pendingIntent);

            StartForeground (NotificationId, notificationBuilder.Build());
        }