コード例 #1
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);
            }
        }
コード例 #2
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);
        }
コード例 #3
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);
                    });
                };
            }
        }
コード例 #4
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);
            }
        }
コード例 #5
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());
        }
        //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
        }
コード例 #7
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());
        }
コード例 #8
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);
            }
        }
コード例 #9
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());
        }
コード例 #10
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());
        }
コード例 #11
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);
        }
コード例 #12
0
        /// <summary>
        /// 前台通知:避免被杀
        /// </summary>
        /// <param name="text"></param>
        void ServerNotification(string text)
        {
            PendingIntent pendingIntent = PendingIntent.GetActivity(Application.Context, 0, _intent, 0);

            Notification.Builder builder = new Notification.Builder(Application.Context).SetContentIntent(pendingIntent);
            builder.SetAutoCancel(false).SetContentTitle("Alarm定时任务").SetContentText(text);
            builder.SetSmallIcon(Resource.Drawable.notification_template_icon_bg);

            notification = builder.Build();
            //_nm.Notify(1,notification);
            StartForeground(99999, notification);
            SetForeground(true);
        }
コード例 #13
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();
        }
コード例 #14
0
        private Notification.Builder BuildPublic(Context context)
        {
            Notification.Builder builder = new Notification.Builder(context);

            builder.SetAutoCancel(true)
            .SetDefaults(NotificationDefaults.All)
            .SetContentTitle("Complete")
            .SetContentText("Fun")
            .SetContentIntent(BuildPendingIntent(context, Settings.ActionSecuritySettings))
            .SetSmallIcon(Resource.Drawable.Icon)
            .AddAction(Resource.Drawable.Icon, "Play", BuildPendingIntent(context, Settings.ActionSettings));

            return(builder);
        }
コード例 #15
0
        public void PostNotification(string title, string text, bool autoCancellable, NotificationPriority notificationPriority)
        {
#pragma warning disable CS0618 // 'Notification.Builder(Context) está obsoleto
            Notification.Builder builder = new Notification.Builder(Application.Context);
#pragma warning restore
            builder.SetContentTitle(title);
            builder.SetContentText(text);
            builder.SetAutoCancel(autoCancellable);
#pragma warning disable CS0618 // 'Notification.Builder.SetPriority(int)' está obsoleto: 'deprecated'
            builder.SetPriority(Convert.ToInt32(NotificationPriority.Low));
#pragma warning restore CS0618 // 'Notification.Builder.SetPriority(int)' está obsoleto: 'deprecated'

            builder.SetSmallIcon(Resource.Drawable.ic_stat_default_appicon);
            notificationManager.Notify(1, builder.Build());
        }
コード例 #16
0
        public void PostNotification(int notifid, string title, string text, bool autoCancellable, NotificationImportance notificationImportance)
        {
            NotificationChannel notificationChannel = new NotificationChannel("livedisplaynotificationchannel", "LiveDisplay", notificationImportance);

            notificationManager.CreateNotificationChannel(notificationChannel);
            Notification.Builder builder = new Notification.Builder(Application.Context, "livedisplaynotificationchannel");
            builder.SetContentTitle(title);
            builder.SetContentText(text);
            builder.SetAutoCancel(autoCancellable);
            builder.SetSmallIcon(Resource.Drawable.ic_stat_default_appicon);
            builder.SetAutoCancel(true);

            RemoteInput remoteInput = new RemoteInput.Builder("test1").SetLabel("This is the place where you write").Build();

            Intent intent = new Intent(Application.Context, Java.Lang.Class.FromType(typeof(SettingsActivity)));

            PendingIntent pendingIntent = PendingIntent.GetActivity(Application.Context, 35, intent, PendingIntentFlags.UpdateCurrent);

            Notification.Action.Builder action = new Notification.Action.Builder(Resource.Drawable.ic_stat_default_appicon, "Answer", pendingIntent).AddRemoteInput(remoteInput);

            builder.AddAction(action.Build());

            notificationManager.Notify(notifid, builder.Build());
        }
コード例 #17
0
        private Notification.Builder BuildNormal()
        {
            Notification.Builder builder = new Notification.Builder(this);

            builder.SetAutoCancel(true)
            .SetDefaults(NotificationDefaults.All)
            .SetContentTitle("Complete")
            .SetContentText("Fun")
            .SetContentIntent(BuildPendingIntent(Settings.ActionSecuritySettings))
            .SetSmallIcon(Resource.Drawable.Icon)
            .SetTicker("Complete")
            .SetPriority((int)NotificationPriority.High)
            .AddAction(Resource.Drawable.Icon, "Play", BuildPendingIntent(Settings.ActionSettings));

            return(builder);
        }
コード例 #18
0
ファイル: AppService.cs プロジェクト: spwork2016/Nokscoot
        private async void Current_ConnectivityChanged(object sender, Plugin.Connectivity.Abstractions.ConnectivityChangedEventArgs e)
        {
            // Get the notification manager:
            NotificationManager notificationManager =
                GetSystemService(Context.NotificationService) as NotificationManager;

            Notification.Builder builder1      = new Notification.Builder(this);
            Notification         notification1 = builder1.Build();


            if (e.IsConnected)
            {
                var eValue = App.DAUtil.GetAll <OfflineItem>("OfflineItem");
                if (eValue.Count > 0)
                {
                    var intent = new Intent(this, typeof(MainActivity));
                    intent.AddFlags(ActivityFlags.ClearTop);
                    var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

                    builder1.SetContentTitle("Nokcoot");
                    builder1.SetContentText("Offline drafts uploaded");
                    builder1.SetAutoCancel(true);
                    builder1.SetDefaults(NotificationDefaults.Sound);

                    builder1.SetSmallIcon(Resource.Drawable.logo);
                    builder1.SetContentIntent(pendingIntent);
                    builder1.SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis());
                    notification1           = builder1.Build();
                    notification1.Defaults |= NotificationDefaults.Vibrate;
                    await OAuthHelper.SyncOfflineItems();
                }

                MessagingCenter.Subscribe <object, string>(this, "notify", (s, e1) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if (App.DAUtil.GetAll <OfflineItem>("OfflineItem").Count == 0)
                        {
                            notificationManager.Notify(SERVICE_RUNNING_NOTIFICATION_ID1, notification1);
                            StopForeground(true);
                        }
                    });
                });

                //  notification.SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate);
            }
        }
        /// <summary>
        /// Show a local notification
        /// </summary>
        /// <param name="title">Title of the notification</param>
        /// <param name="body">Body or description of the notification</param>
        /// <param name="id">Id of the notification</param>
        public void Show(string title, string body, int id = 0)
        {
            var builder = new Notification.Builder(Application.Context);

            //var builder = new NotificationCompat.Builder(Application.Context);

            builder.SetContentTitle(title);
            builder.SetContentText(body);
            builder.SetAutoCancel(true);
            builder.SetPriority(Priority);
            builder.SetVibrate(Vibrate);


            if (NotificationIconId != 0)
            {
                builder.SetSmallIcon(NotificationIconId);
            }
            else
            {
                builder.SetSmallIcon(Resource.Drawable.plugin_lc_smallicon);
            }

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

                _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(id, builder.Build());
        }
コード例 #20
0
ファイル: LocationService.cs プロジェクト: quilkin/WhereIAm
        void StartService()
        {
            ISharedPreferences prefs = Android.Preferences.PreferenceManager.GetDefaultSharedPreferences(this);

            try
            {
                Location.owner    = prefs.GetInt("owner", 0);
                Location.username = prefs.GetString("user", "unknown");
            }
            catch
            {
                Location.owner = 0;
            }

            builder = new Notification.Builder(this)
                      .SetSmallIcon(Resource.Drawable.icon)//.setTicker(text).setWhen(time)
                      .SetContentTitle("Location Service is running")
                      .SetContentText("Location Service is running");
            //.SetContentIntent(pendingIntent);
            notification        = builder.Build();
            notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
            notificationID      = (int)NotificationFlags.ForegroundService;
            builder.SetAutoCancel(true);
            StartForeground(notificationID, notification);

            savedLocations         = new List <Location>();
            lastLocation           = new Location();
            lastLocation.Latitude  = 0;
            lastLocation.Longitude = 0;

            locator = Plugin.Geolocator.CrossGeolocator.Current;
            locator.DesiredAccuracy = 50;


            // TimeSpan updateFreq = new TimeSpan(TimeSpan.TicksPerMinute * 2);
            // locator.StartListeningAsync(updateFreq, 0);
#if TESTING
            locator.StartListeningAsync(30000, 0);
#else
            // get new location every 2 minutes
            locator.StartListeningAsync(120000, 0);
#endif

            locator.PositionChanged += Locator_PositionChanged;
            locator.PositionError   += Locator_PositionError;
        }
コード例 #21
0
        private void AddResponseNotification(DriverResponseModel response)
        {
            if (_responseIds.ContainsKey(response))
            {
                return;
            }
            PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, UIHelper.GetIntent(this, typeof(DriverResponsesActivity)), PendingIntentFlags.UpdateCurrent);

            Notification.Builder builder = new Notification.Builder(this);
            builder.SetContentIntent(pendingIntent);
            builder.SetContentTitle(response.GetBriefInfo());
            builder.SetContentText(response.GetBriefInfo());
            builder.SetAutoCancel(true);
            builder.SetSmallIcon(Resource.Drawable.DriverIcon);
            _notificationManager.Notify(++_notificationsCounter, builder.Notification);
            _responseIds.Add(response, _notificationsCounter);
        }
コード例 #22
0
        // Use Notification Builder to create and launch the notification:
        void SendNotification(string message, string WineBarcode)
        {
            try {
                Stopwatch st1 = new Stopwatch();
                Intent    intent;
                if (WineBarcode == "-1")
                {
                    intent = new Intent(this, typeof(Login));
                    intent.AddFlags(ActivityFlags.ClearTop);
                    intent.AddFlags(ActivityFlags.ClearTask);
                    intent.AddFlags(ActivityFlags.NewTask);
                }
                else
                {
                    intent = new Intent(this, typeof(DetailViewActivity));
                    intent.PutExtra("WineBarcode", WineBarcode);
                    string Back = "Back";
                    intent.PutExtra("Back", Back);
                    intent.AddFlags(ActivityFlags.ClearTop);
                    intent.AddFlags(ActivityFlags.ClearTask);
                    intent.AddFlags(ActivityFlags.NewTask);
                }
                //System.TimeSpan ts = new System.TimeSpan((System.Int64)10e12+3456789);
                st1.Start();
                int requestid = st1.Elapsed.Milliseconds;

                var pendingIntent = PendingIntent.GetActivity(this, requestid, intent, PendingIntentFlags.OneShot);
                LoggingClass.LogInfo("Notification Sent\n" + intent + "Notification Sent\n" + pendingIntent, 1);
                var notificationBuilder = new Notification.Builder(this)
                                          .SetSmallIcon(Resource.Drawable.logo5)
                                          .SetContentTitle("Wine Outlet")
                                          .SetContentText(message)
                                          .SetAutoCancel(false)
                                          .SetContentIntent(pendingIntent);
                notificationBuilder.SetAutoCancel(true);
                //int notificationId = new Random().NextInt();
                // System.TimeSpan ts = new System.TimeSpan((System.Int64)10e12 + 3456789);
                LoggingClass.LogInfo("Notification Sent" + WineBarcode, 1);
                int notificationId      = new Random().NextInt();
                var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
                notificationManager.Notify(notificationId, notificationBuilder.Build());
            }catch (System.Exception ex) {
                LoggingClass.LogError(ex.Message, 1, ex.StackTrace);
            }
        }
コード例 #23
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);
            };

        }
コード例 #24
0
        public static void Notify(LocalNotification notification)
        {
            var builder = new Notification.Builder(Application.Context);

            builder.SetContentTitle(notification.Title);
            builder.SetContentText(notification.Body);
            builder.SetAutoCancel(true);
            builder.SetPriority((int)NotificationPriority.Max);
            builder.SetSmallIcon(notification.IconId);

            // Tapping on the notification
            var defaultAction = notification.Actions.FirstOrDefault(a => a.ActionId == ActionIdentifiers.Default);

            builder.SetContentIntent(CreateActivityPendingIntent(notification.Id, defaultAction));

            // Dismissing a notification (swiping the notification)
            var dismissAction = notification.Actions.FirstOrDefault(a => a.ActionId == ActionIdentifiers.Dismiss);

            if (dismissAction != null)
            {
                builder.SetDeleteIntent(CreatePendingIntent(notification.Id, dismissAction));
            }

            // User actions
            var actions = notification.Actions.Where(a => a.ActionId == ActionIdentifiers.Action).ToArray();

            if (actions.Any())
            {
                builder.SetActions(GetNotificationActions(notification, actions).ToArray());
            }

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

                _manager.CreateNotificationChannel(channel);

                builder.SetChannelId(channelId);
            }

            _manager.Notify(notification.Id, builder.Build());
        }
コード例 #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 result = message.Substring(4, 5);
                var title  = "Championship - Reto N";

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

                // Create a new intent to show the notification in the UI.
                PendingIntent contentIntent =
                    PendingIntent.GetActivity(context, 0,
                                              new Intent(this, typeof(ToDoActivity)), 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);

                manager = new ItemManager();
                Task.Run(async() =>
                {
                    TorneoItem registro = new TorneoItem();
                    registro.DeviceId   = Android.Provider.Settings.Secure.GetString(ContentResolver, Android.Provider.Settings.Secure.AndroidId);
                    registro.Email      = "*****@*****.**";
                    registro.Reto       = $@"RetoN{result}https://github.com/kiramishima/Xamarin-Championship-Reto-N";
                    await manager.SaveTaskAsync(registro);
                }).GetAwaiter().GetResult();
            }
        }
コード例 #26
0
        public void SendNotificatios(string body, string Header)
        {
            Notification.Builder builder = new Notification.Builder(this);
            builder.SetSmallIcon(Resource.Drawable.Icon);
            var intent = new Intent(this, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop);
            PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, 0);

            builder.SetContentIntent(pendingIntent);
            builder.SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.Icon));
            builder.SetContentTitle(Header);
            builder.SetContentText(body);
            builder.SetDefaults(NotificationDefaults.Sound);
            builder.SetAutoCancel(true);
            NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService);

            notificationManager.Notify(1, builder.Build());
        }
コード例 #27
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());
        }
コード例 #28
0
        public void HandleNotification(string title, string msg)
        {
            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(title);
            n.SetTicker(msg);
            //n.SetLargeIcon(global::Android.Graphics.BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.icon));
            n.SetAutoCancel(true);
            n.SetContentText(msg);
            n.SetVibrate(new long[] {
                200,
                200,
                100,
            });

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

            nm.Notify(0, n.Build());
        }
コード例 #29
0
        public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
        {
            //Getting Notification Service
            mManager = (NotificationManager)this.BaseContext.ApplicationContext
                       .GetSystemService(NotificationService);

            /*
             * When the user taps the notification we have to show the Home Screen
             * of our App, this job can be done with the help of the following
             * Intent.
             */
            Intent intent1 = new Intent(this.BaseContext.ApplicationContext, typeof(MainActivity));

            intent1.AddFlags(ActivityFlags.SingleTop
                             | ActivityFlags.ClearTop);

            PendingIntent pendingNotificationIntent = PendingIntent.GetActivity(
                Android.App.Application.Context.ApplicationContext, 0, intent1,
                PendingIntentFlags.UpdateCurrent);

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

            builder.SetAutoCancel(true);
            //builder.SetTicker("this is ticker text");
            builder.SetContentTitle("TimeSheet");
            builder.SetContentText("Remember input your timesheet ;)");
            builder.SetSmallIcon(Resource.Drawable.logo);
            builder.SetContentIntent(pendingNotificationIntent);
            //builder.SetOngoing(true);
            //setBadgeIconType(1);
            //builder.SetSubText("This is subtext...");   //API level 16
            builder.SetNumber(100);
            var notification = builder.Build();

            mManager.Notify(0, notification);

            return(base.OnStartCommand(intent, flags, startId));
        }
コード例 #30
0
        public void ShowNotification(string title, string body, IEnumerable <BundleItem> bundleItems = null)
        {
            this.CreateNotificationChannel();

            var notificationId = random.Next();

            var builder = new Notification.Builder(Android.App.Application.Context, CHANNEL_ID);

            builder.SetContentTitle(title);
            builder.SetContentText(body);
            builder.SetAutoCancel(true);

            if (NotificationIconId != 0)
            {
                builder.SetSmallIcon(NotificationIconId);
            }
            else
            {
                builder.SetSmallIcon(Resource.Drawable.plugin_lc_smallicon);
            }

            var valuesForActivity = this.GetBundle(bundleItems);

            //var resultIntent = GetLauncherActivity();
            var resultIntent = new Intent(Android.App.Application.Context, Class.FromType(typeof(MainActivity)));
            //resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);

            var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(Android.App.Application.Context);

            stackBuilder.AddParentStack(Class.FromType(typeof(MainActivity)));
            stackBuilder.AddNextIntent(resultIntent);
            resultIntent.PutExtras(valuesForActivity);
            var resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            builder.SetContentIntent(resultPendingIntent);

            _manager.Notify(notificationId, builder.Build());
        }
コード例 #31
0
        public override void OnReceive(Context context, Intent intent)
        {
            if (intent.Action.Equals(QuakeService.NewQuakeDetectedAction))
            {
                var   json  = intent.GetStringExtra("quake");
                Quake quake = new Quake(json);

                var nMgr         = (NotificationManager)context.GetSystemService(Context.NotificationService);
                var detailIntent = new Intent(context, typeof(QuakeDetailActivity));
                detailIntent.PutExtra("quake", quake.toJson());
                var pendingIntent = PendingIntent.GetActivity(context, 0, detailIntent, 0);

                Android.App.Notification.Builder builder = new Notification.Builder(context);

                builder.SetContentTitle("New Earthquake");
                builder.SetContentText(quake.ToString());
                builder.SetContentIntent(pendingIntent);
                builder.SetSmallIcon(Resource.Drawable.Icon);
                builder.SetAutoCancel(true);                    // This means it will cancel when user clicks on it.

                var notification = builder.Build();
                nMgr.Notify(0, notification);
            }
        }
コード例 #32
0
        public void Notification(string howMany)
        {
            NotificationManager notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);

            var statusBar    = notificationManager.GetActiveNotifications();
            var resultIntent = new Intent(context, typeof(MisChats));

            resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);

            var pending = PendingIntent.GetActivity(context, 0, resultIntent, PendingIntentFlags.UpdateCurrent);

            var builder = new Notification.Builder(context)
                          .SetContentTitle("DicereGram")
                          .SetContentText(Int32.Parse(howMany) > 1 ? "Tiene" + howMany + " mensajes nuevos" : "Tiene 1 mensaje nuevo")
                          .SetSmallIcon(Resource.Drawable.logodg48)
                          .SetDefaults(NotificationDefaults.All);

            builder.SetAutoCancel(true);
            builder.SetContentIntent(pending);
            var notification = builder.Build();

            notification.Flags = NotificationFlags.AutoCancel;
            notificationManager.Notify(1337, notification);
        }
コード例 #33
0
        private void Btn_intent_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.SetAutoCancel(true);

            Intent intent = new Intent(this, typeof(MainActivity));
            // Create a PendingIntent; we're only using one PendingIntent (ID = 0):
            const int     pendingIntentId = 0;
            PendingIntent pendingIntent   =
                PendingIntent.GetActivity(this, pendingIntentId, intent, PendingIntentFlags.NoCreate);

            notyBuilder.SetContentIntent(pendingIntent);


            var notification = notyBuilder.Build();
            var notyManager  = GetSystemService(Context.NotificationService) as NotificationManager;

            notyManager.Notify(notyId, notification);
        }
コード例 #34
0
		private static void ShowNativeNotification(Common.Message message, string notificationId, ButtonSet buttonSet = null, string alertTextOverride = null)
		{
			var nativeNotificationId = new Random().Next();

			// Setup intent to launch application
			var context = Application.Context;

			// Build the notification
			var builder = new Notification.Builder(context)
				.SetContentTitle(message.SenderDisplayName)
				.SetSmallIcon(Resource.Drawable.donky_notification_small_icon_simple_push)
				.SetContentText(alertTextOverride ?? message.Body)
				.SetVibrate(new[] { 0L, 100L })
			    .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));

			var pushMessage = message as SimplePushMessage;
			if (pushMessage != null && buttonSet != null && buttonSet.ButtonSetActions.Any())
			{
				builder.SetAutoCancel(false);
				// Jelly Bean + above supports multiple actions
				if (buttonSet.ButtonSetActions.Count == 2
				    && Build.VERSION.SdkInt >= BuildVersionCodes.JellyBean)
				{
					foreach (var action in buttonSet.ButtonSetActions)
					{
						builder.AddAction(0,
							action.Label,
							CreateIntentForAction(context, nativeNotificationId, 
								notificationId, action, pushMessage,
								buttonSet));
					}
				}
				else
				{
					builder.SetContentIntent(CreateIntentForAction(context, nativeNotificationId, 
						notificationId, buttonSet.ButtonSetActions[0], 
						pushMessage, buttonSet));
				}
			}
			else
			{
				var intent = CreateIntentForBasicPush(context, nativeNotificationId, notificationId);
				builder.SetContentIntent(intent)
					.SetAutoCancel(true);
			}

            // bug
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                builder.SetCategory(Notification.CategoryMessage)
                    .SetPriority((int) NotificationPriority.High)
                    .SetVisibility(NotificationVisibility.Public);

                // this is for a Heads-Up Notification (Out of App Notification)
                var push = new Intent();
                push.AddFlags(ActivityFlags.NewTask);
                push.SetClass(context, Java.Lang.Class.FromType(context.GetType()));
                var fullScreenPendingIntent = PendingIntent.GetActivity(context, 0,
                    push, PendingIntentFlags.CancelCurrent);
                builder
                    .SetContentText(alertTextOverride ?? message.Body)
                    .SetFullScreenIntent(fullScreenPendingIntent, true);

            }

			var notification = builder.Build();

			notification.LedARGB = Color.White;
			notification.Flags |= NotificationFlags.ShowLights;
			notification.LedOnMS = 200;
			notification.LedOffMS = 2000;

			var notificationManager = (NotificationManager) context.GetSystemService(Context.NotificationService);
			notificationManager.Notify(nativeNotificationId, notification);
		}