예제 #1
0
        public void SetNotification(Esms sms)
        {
            Intent notiIntent = new Intent(MainActivity.CurrentContext, typeof(MainActivity));

            notiIntent.PutExtra("sms", "1");
            PendingIntent pendingIntent = PendingIntent.GetActivity(MainActivity.CurrentContext, 0, notiIntent, PendingIntentFlags.UpdateCurrent);

            NotificationCompat.Builder notification = new NotificationCompat.Builder(MainActivity.CurrentContext, MainActivity.CHANNEL_ID)
                                                      .SetContentTitle("Service")
                                                      .SetContentIntent(pendingIntent)
                                                      .SetAutoCancel(true)
                                                      .SetContentText("El servicio de notificaciones está ejecutandose.")
                                                      .SetSmallIcon(Resource.Drawable.ic_announcement_black_48dp);

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

            // Publish the notification:

            notificationManager.Notify(sms.Id, notification.Build());
        }
예제 #2
0
        public void ShowNotification(string title, string message)
        {
            var intent = new Intent(Android.App.Application.Context, typeof(MainActivity));

            intent.PutExtra("TestID", "test");
            intent.AddFlags(ActivityFlags.ClearTop);

            var pendingIntent = PendingIntent.GetActivity(Android.App.Application.Context, 0, intent, PendingIntentFlags.Immutable);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(Android.App.Application.Context)
                                                 .SetAutoCancel(true)
                                                 .SetContentIntent(pendingIntent)
                                                 .SetContentTitle("Button Clicked")                                           // Set the title
                                                 .SetSmallIcon(Resource.Mipmap.ic_launcher)                                   // This is the icon to display
                                                 .SetContentText(String.Format("The button has been clicked {0} times.", 3)); // the message to display.

            Notification notification = builder.Build();

            const int notificationId = 0;

            _manager.Notify(notificationId, builder.Build());
        }
예제 #3
0
        private void AndroidEnvironmentOnUnhandledExceptionRaiser(object sender, RaiseThrowableEventArgs e)
        {
            try
            {
                Intent intent = new Intent(this.activity, typeof(SpalshScreen_Activity));
                intent.AddCategory(Intent.CategoryHome);
                intent.PutExtra("crash", true);
                intent.SetAction(Intent.ActionMain);
                intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask | ActivityFlags.ClearTask);

                PendingIntent pendingIntent = PendingIntent.GetActivity(MainApplication.GetInstance().BaseContext, 0, intent, PendingIntentFlags.OneShot);
                AlarmManager  mgr           = (AlarmManager)MainApplication.GetInstance().BaseContext.GetSystemService(Context.AlarmService);
                mgr.Set(AlarmType.Rtc, JavaSystem.CurrentTimeMillis() + 100, pendingIntent);

                this.activity.Finish();
                JavaSystem.Exit(2);
            }
            catch (Exception exception)
            {
                Crashes.TrackError(exception);
            }
        }
예제 #4
0
        void SendNotification(string messageBody, string title, string actionClick)
        {
            Intent    intent          = new Intent(this, typeof(MainActivity));
            const int pendingIntentId = 0;

            PendingIntent.GetActivity(this, pendingIntentId, intent, PendingIntentFlags.OneShot);
            PendingIntent pendingIntent       = GetIntentOrder(actionClick);
            var           notificationBuilder = new NotificationCompat.Builder(this)
                                                .SetSmallIcon(Resource.Drawable.icon)
                                                .SetContentTitle(title)
                                                .SetContentText(messageBody)
                                                .SetAutoCancel(true)
                                                .SetContentIntent(pendingIntent)
                                                .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.All))
                                                .SetDefaults((int)NotificationDefaults.All)
                                                .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Ringtone))
                                                .SetPriority((int)NotificationPriority.High)
                                                .SetVisibility((int)NotificationVisibility.Public);
            var notificationManager = NotificationManagerCompat.From(this);

            notificationManager.Notify(100, notificationBuilder.Build());
        }
예제 #5
0
        private void SendLocalNotification(string messageBody, string id)
        {
            var intent = new Intent(this, typeof(NotificationNavigationActivity));

            intent.AddFlags(ActivityFlags.PreviousIsTop);//.ClearTop);
            intent.PutExtra("Notification Type", "Notification");
            intent.PutExtra("Id", id);
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

            var notificationBuilder = new NotificationCompat.Builder(this)
                                      .SetSmallIcon(Resource.Drawable.icon)
                                      .SetContentTitle("New Feature Available")
                                      .SetTicker("New Feature Available")
                                      .SetContentText("New Feature Available")
                                      .SetContentIntent(pendingIntent)
                                      .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                      .SetAutoCancel(true);

            var notificationManager = NotificationManager.FromContext(this);

            notificationManager.Notify(0 /* ID of Notification */, notificationBuilder.Build());
        }
예제 #6
0
        public void Notify(int rate)
        {
            try
            {
                contentView.SetProgressBar(Resource.Id.progress, 100, rate, false);
                contentView.SetTextViewText(Resource.Id.notificationTitle, "正在下载更新");
                contentView.SetTextViewText(Resource.Id.notificationPercent, rate + "%");

                notification.ContentView = contentView;
                notification.Flags       = NotificationFlags.ForegroundService;
                notification.Icon        = Resource.Drawable.icon;
                p = PendingIntent.GetActivity(Application.Context.ApplicationContext, 0, new Intent(Intent.ActionView), 0);
                notification.ContentIntent = p;

                // Publish the notification:
                const int notificationId = 0;
                notificationManager.Notify(notificationId, notification);
            }
            catch (Exception)
            {
            }
        }
예제 #7
0
        private void StartForeground()
        {
            //Intent for showing notification
            var pendingIntent = PendingIntent.GetActivity(ApplicationContext, 0,
                                                          new Intent(ApplicationContext, typeof(MainActivity)),
                                                          PendingIntentFlags.UpdateCurrent);

            //Custom notification and build it
            var builder = new Notification.Builder(this)
                          .SetContentText("Radio is playing")
                          .SetContentTitle("Listen Radio")
                          .SetContentIntent(pendingIntent)
                          .SetSmallIcon(Resource.Drawable.Icon)
                          .SetOngoing(true);
            Notification notification = builder.Build();

            //Init notification manager and show notification
            NotificationManager notificationManager =
                GetSystemService(Context.NotificationService) as NotificationManager;

            notificationManager.Notify(NotificationId, notification);
        }
        private Notification CreateNotification()
        {
            var builder = new NotificationCompat.Builder(this, ChannelId);

            var newIntent = new Intent(this, typeof(AndroidMainActivity));

            newIntent.PutExtra("LiveGeolocationTrackingExtra", true);
            newIntent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);

            var pendingIntent = PendingIntent.GetActivity(this, 0, newIntent, PendingIntentFlags.UpdateCurrent);
            var notification  = builder.SetContentIntent(pendingIntent)
                                .SetSmallIcon(Resource.Drawable.wasabee)
                                .SetAutoCancel(false)
                                .SetTicker("Wasabee location sharing")
                                .SetContentTitle("Wasabee")
                                .SetContentText($"Sharing your location.\r\nLast update at {_lastUpdateTime:T}")
                                .SetChannelId(ChannelId)
                                .SetSound(null)
                                .Build();

            return(notification);
        }
예제 #9
0
        private void AndroidEnvironmentOnUnhandledExceptionRaiser(object sender, RaiseThrowableEventArgs e)
        {
            try
            {
                Intent intent = new Intent(Activity, typeof(SplashScreenActivity));
                intent.AddCategory(Intent.CategoryHome);
                intent.PutExtra("crash", true);
                intent.SetAction(Intent.ActionMain);
                intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask | ActivityFlags.ClearTask);

                PendingIntent pendingIntent = PendingIntent.GetActivity(GetInstance().BaseContext, 0, intent, PendingIntentFlags.OneShot);
                AlarmManager  mgr           = (AlarmManager)GetInstance()?.BaseContext?.GetSystemService(AlarmService);
                mgr?.Set(AlarmType.Rtc, JavaSystem.CurrentTimeMillis() + 100, pendingIntent);

                Activity.Finish();
                JavaSystem.Exit(2);
            }
            catch (Exception exception)
            {
                Methods.DisplayReportResultTrack(exception);
            }
        }
예제 #10
0
        void createNotification(string title, string desc)
        {
            //Create notification
            var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;

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

            //Create the notification
            var notification = new Notification(Android.Resource.Drawable.SymActionEmail, title);

            //Auto cancel will remove the notification once the user touches it
            notification.Flags = NotificationFlags.AutoCancel;

            //Set the notification info
            //we use the pending intent, passing our ui intent over which will get called
            //when the notification is tapped.
            notification.SetLatestEventInfo(this, title, desc, PendingIntent.GetActivity(this, 0, uiIntent, 0));

            //Show the notification
            notificationManager.Notify(1, notification);
        }
예제 #11
0
        private void addNotification()
        {
            // create the pending intent and add to the notification
            var intent = this.PackageManager.GetLaunchIntentForPackage(this.PackageName); // opens app from background ( Can we use this auto open app with alert? )
                                                                                          // intent.AddFlags(ActivityFlags.ClearTop);
                                                                                          //Intent intent = new Intent(this, typeof(BackgroundService));
            PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent);
            var           lastLogin     = "******";

            // string lastLogin =  as string;
            if (Xamarin.Forms.Application.Current.Properties.Count > 0)
            {
                if (Xamarin.Forms.Application.Current.Properties[Constants.CURRENT_DATE] != null)
                {
                    lastLogin = "******" + Xamarin.Forms.Application.Current.Properties[Constants.CURRENT_DATE].ToString();
                }
            }
            string deviceModel = DeviceModal;

            Xamarin.Forms.Application.Current.Properties[Constants.DEVICE_MODEL] = deviceModel;

            // create the notification
            Notification.Builder m_notificationBuilder = new Notification.Builder(this)
                                                         .SetContentTitle("AssetChain")
                                                         .SetContentText(lastLogin)
                                                         .SetSmallIcon(Resource.Drawable.logo)
                                                         .SetContentIntent(pendingIntent);

            Notification notification = m_notificationBuilder.Build();

            notification.Flags = NotificationFlags.AutoCancel;

            // send the notification
            const int           NOTIFICATION_ID     = 101;
            NotificationManager notificationManager = this.GetSystemService(Context.NotificationService) as NotificationManager;

            StartForeground(NOTIFICATION_ID, notification); // locks notificaion in bar
            notificationManager.Notify(NOTIFICATION_ID, m_notificationBuilder.Build());
        }
예제 #12
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            _nfc_avaible = false;
            _do_scanning = false;
            _nfc_adapter = NfcAdapter.GetDefaultAdapter(this);

            if (_nfc_adapter != null)
            {
                _nfc_avaible    = true;
                _pending_intent = PendingIntent.GetActivity(this, 0, new Intent(this, GetType()).AddFlags(ActivityFlags.SingleTop), 0);
                _filters        = new IntentFilter[] { new IntentFilter(NfcAdapter.ActionTagDiscovered) };
            }

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            txtStatus            = (TextView)FindViewById(Resource.Id.txtStatus);
            btnGetSAMInfo        = (Button)FindViewById(Resource.Id.btnGetSAMInfo);
            btnGetSAMInfo.Click += onClickGetSAMInfo;

            getVersionAPDUs.Add(SAMType.Mifare, new byte[] { (byte)0x80, (byte)0x60, (byte)0x00, (byte)0x00, /*(byte)0x00,*/ (byte)0x00 });
            getVersionAPDUs.Add(SAMType.Felica, new byte[] { (byte)0xA0, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x05, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xE6, (byte)0x00, (byte)0x00 });

            nfcAdapter = NfcAdapter.GetDefaultAdapter(this);

            if (nfcAdapter == null)
            {
                Toast.MakeText(this, GetString(Resource.String.message_nfc_not_supported), ToastLength.Long).Show();
                Finish();
                return;
            }

            nfcIntent = PendingIntent.GetActivity(this, 0,
                                                  new Intent(this, this.Class)
                                                  .AddFlags(ActivityFlags.SingleTop), 0);

            //The EMDKManager object will be created and returned in the callback.
            EMDKResults results = EMDKManager.GetEMDKManager(Application.Context, this);

            //Check the return status of EMDKManager object creation.
            if (results.StatusCode == EMDKResults.STATUS_CODE.Success)
            {
                //EMDKManager object creation success
            }
            else
            {
                //EMDKManager object creation failed
            }
        }
예제 #14
0
        public override void OnReceive(Context context, Intent intent)
        {
            var intent1 = new Intent(context, typeof(MainActivity));

            intent1.AddFlags(ActivityFlags.ClearTop);
            var    extra         = intent.GetStringExtra(LocalNotificationKey);
            var    notification  = DeserializeNotification(extra);
            string CHANNEL_ID    = "my_channel_id_01";
            Random random        = new Random();
            int    randomNumber  = random.Next(9999 - 1000) + 1000;
            var    pendingIntent = PendingIntent.GetActivity(Application.Context, randomNumber, intent1, PendingIntentFlags.OneShot);

            // var resultIntent = LocalNotificationService.GetLauncherActivity();

            NotificationCompat.Builder builder = new NotificationCompat.Builder(Application.Context, CHANNEL_ID)
                                                 .SetContentTitle(notification.Title)
                                                 .SetContentText(notification.Body)
                                                 .SetContentIntent(pendingIntent)
                                                 .SetSmallIcon(Resource.Drawable.icon);

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



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

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

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

            notificationManager.Notify(notificationId, notification1);
        }
예제 #15
0
        public override void OnReceive(Context context, Intent intent)
        {
            System.Diagnostics.Debug.WriteLine("Alarm {0} {1}", DateTime.Now, "ups");

            //Every time the `RepeatingAlarm` is fired, set the next alarm
            //Intent intent = new Intent(context, typeof(RepeatingAlarm));
            PendingIntent source = PendingIntent.GetBroadcast(context, 0, intent, 0);
            AlarmManager  am     = (AlarmManager)context.GetSystemService(Context.AlarmService);
            LsMqtt        mqtt   = App.Web.GetLastState("Gustav");

            if (mqtt != null)
            {
                mqtt.Dat.Firmware = "1.23";
                App.History.Add(new HistoryItem(DateTime.Now, mqtt));

                //Context context = Android.App.Application.Context;
                //AlarmManager am = (AlarmManager)context.GetSystemService(Context.AlarmService);
                NotificationManager nm = (NotificationManager)context.GetSystemService(Context.NotificationService);

                if (App.NotifyMsg(mqtt.Dat))
                {
                    var notIntent     = new Intent(context, typeof(MainActivity));
                    var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);

                    var builder = new NotificationCompat.Builder(context, MainActivity.cn)
                                  .SetAutoCancel(true)                         // Dismiss the notification from the notification area when the user clicks on it
                                  .SetContentIntent(contentIntent)             // Start up this activity when the user clicks the intent.
                                  .SetContentTitle("Notify")                   // Set the title
                                                                               //.SetNumber(count) // Display the count in the Content Info
                                  .SetSmallIcon(Resource.Drawable.Icon_Notify) // This is the icon to display
                                  .SetContentText(mqtt.Dat.State.ToString());  // the message to display.

                    nm.Notify(1000, builder.Build());
                }
            }
            am.SetAndAllowWhileIdle(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime() + 5 * 60 * 1000, source);
            //Toast.MakeText(context, "repeating_received and after 15s another alarm will be fired", ToastLength.Short).Show();
        }
예제 #16
0
        public void Notify(string title, string body, string clickAction, Dictionary <string, string> data)
        {
            Logger.CmWrite(TAG, $"{title}, {body}, {Count}");
            Count++;

            var intent = new Intent(clickAction)
                         .AddFlags(ActivityFlags.SingleTop);

            if (data != null)
            {
                foreach (string key in data.Keys)
                {
                    intent.PutExtra(key, data[key]);
                }
            }

            var pendingIntent = PendingIntent.GetActivity(Parent,
                                                          NotifyId,
                                                          intent,
                                                          PendingIntentFlags.OneShot);

            var notificationBuilder = new NotificationCompat.Builder(Parent, ChannelId)
                                      .SetAutoCancel(true)
                                      .SetContentIntent(pendingIntent)
                                      .SetContentTitle(title)
                                      .SetPriority(Priority)
                                      .SetContentText(body);

            if (IconId != 0)
            {
                notificationBuilder.SetSmallIcon(IconId);
            }


            var notificationManager = NotificationManagerCompat.From(Parent);

            notificationManager.Notify(NotifyId, notificationBuilder.Build());
        }
예제 #17
0
        public override void OnReceive(Context context, Intent intent)
        {

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

            var notIntent = new Intent(context, typeof(MainActivity));
            var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);
            //var manager = NotificationManagerCompat.From(context);

            
            var chan = new NotificationChannel(CHANNEL, "Notification", NotificationImportance.High)
            {
                LockscreenVisibility = NotificationVisibility.Public
            };

            int resourceId;
            resourceId = Resource.Drawable.icon;

            //Generate a notification with just short text and small icon
            var builder = new NotificationCompat.Builder(context)
                            .SetContentIntent(contentIntent)
                            .SetSmallIcon(Resource.Drawable.home_ico)
                            .SetContentTitle(title)
                            .SetContentText(message)
                            .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                            .SetChannelId(CHANNEL)
                            .SetAutoCancel(true);
            //.SetVisibility(NotificationVisibility.Public);


            NotificationManager manager = (NotificationManager)Android.App.Application.Context.GetSystemService(Context.NotificationService);
            manager.CreateNotificationChannel(chan);

            var notification = builder.Build();
            manager.Notify(0, notification);
            
        }
        /// <summary>
        /// Handles the notification to ensure the Notification manager is updated to alert the user
        /// </summary>
        private void SendNotification(PushNotification push)
        {
            // Create relevant non-repeatable Id to allow multiple notifications to be displayed in the Notification Manager
            Int32 notificationId = Int32.Parse(DateTime.Now.ToString("MMddHHmmsss"));

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

            intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
            intent.PutExtra("Area", push.Area);
            intent.PutExtra("ExtraInfo", push.ExtraInfo);

            PendingIntent pendingIntent = PendingIntent.GetActivity(this, notificationId, intent, PendingIntentFlags.UpdateCurrent);

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

            // Set BigTextStyle for expandable notifications
            NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
            bigTextStyle.SetSummaryText(push.Body);
            bigTextStyle.SetSummaryText(String.Empty);

            Int64 timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();

            Notification notification = new NotificationCompat.Builder(this, NotificationChannelId)
                                        .SetSmallIcon(Resource.Drawable.ic_launcher)
                                        .SetContentTitle(push.Title)
                                        .SetContentText(push.Body)
                                        .SetStyle(bigTextStyle)
                                        .SetPriority(NotificationCompat.PriorityHigh)
                                        .SetWhen(timestamp)
                                        .SetShowWhen(true)
                                        .SetContentIntent(pendingIntent)
                                        .SetAutoCancel(true)
                                        .Build();

            notificationManager.Notify(notificationId, notification);

            notificationManager.Notify(notificationId, notification);
        }
        internal void InitMediaSession(string packageName, MediaServiceBinder binder)
        {
            try
            {
                if (mediaSessionCompat == null)
                {
                    Intent        nIntent = new Intent(applicationContext, typeof(MediaPlayer));
                    PendingIntent pIntent = PendingIntent.GetActivity(applicationContext, 0, nIntent, 0);

                    RemoteComponentName   = new ComponentName(packageName, new RemoteControlBroadcastReceiver().ComponentName);
                    mediaSessionCompat    = new MediaSessionCompat(applicationContext, "XamarinStreamingAudio", RemoteComponentName, pIntent);
                    mediaControllerCompat = new MediaControllerCompat(applicationContext, mediaSessionCompat.SessionToken);
                    NotificationManager   = new MediaNotificationManagerImplementation(applicationContext, CurrentSession.SessionToken, _serviceType);
                }
                mediaSessionCompat.Active = true;
                MediaServiceBase            mediaServiceBase = binder.GetMediaPlayerService <MediaServiceBase>();
                MediaSessionCompat.Callback remoteCallback   = mediaServiceBase.AlternateRemoteCallback;
                if (remoteCallback == null)
                {
                    remoteCallback = new MediaSessionCallback(this);
                }
                try
                {
                    mediaSessionCompat.SetCallback(remoteCallback);
                }
                catch (Exception ex2)
                {
                    Console.WriteLine(ex2);
                }
                mediaSessionCompat?.SetFlags(MediaSessionCompat.FlagHandlesMediaButtons | MediaSessionCompat.FlagHandlesTransportControls);
                _packageName = packageName;
                _binder      = binder;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        void SendNotification(string messageBody)
        {
            int notifyID = 1;
            // The id of the channel.
            var importance = NotificationImportance.High;

            NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, "ELGASCLIENTENOTIFICATIONS", importance);

            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.OneShot);

            // Instantiate the builder and set notification elements, including pending intent:
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
                                                 .SetContentIntent(pendingIntent)
                                                 .SetContentTitle("EL GAS")
                                                 .SetAutoCancel(true)
                                                 .SetVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
                                                 .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                                 .SetContentText(messageBody)
                                                 .SetSmallIcon(Resource.Drawable.ic_launcher)
                                                 .SetChannelId(CHANNEL_ID);

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

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

            mNotificationManager.CreateNotificationChannel(mChannel);

            // Publish the notification:
            mNotificationManager.Notify(notifyID, notification);
        }
예제 #21
0
        void SendNotification(string message)
        {
            try
            {
                Console.WriteLine("SendNotification");
                var notificationManager = NotificationManagerCompat.From(this);

                Console.WriteLine("Created Manager");
                var notificationIntent = new Intent(this, typeof(MainActivity));
                notificationIntent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);
                var pendingIntent = PendingIntent.GetActivity(this, 0, notificationIntent, PendingIntentFlags.UpdateCurrent);

                Console.WriteLine("Created Pending Intent");

                var style = new NotificationCompat.BigTextStyle();
                style.BigText(message);

                var builder = new NotificationCompat.Builder(this)
                              .SetContentIntent(pendingIntent)
                              .SetContentTitle("Developer Open Space")
                              .SetAutoCancel(true)
                              .SetStyle(style)
                              .SetSmallIcon(Resource.Drawable.ic_notification)
                              .SetContentText(message);

                // Obtain a reference to the NotificationManager
                var id = open.conference.app.Droid.Helpers.Settings.GetUniqueNotificationId();
                Console.WriteLine("Got Unique ID: " + id);
                var notif = builder.Build();
                notif.Defaults = NotificationDefaults.All;
                Console.WriteLine("Notify");
                notificationManager.Notify(id, notif);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
예제 #22
0
        void CreateNotification(string title, string desc, string image)
        {
            //Create notification
            var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
            //Create an intent to show ui
            var uiIntent = new Intent(this, typeof(MainActivity));

            //Use Notification Builder
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
            //Create the notification
            //we use the pending intent, passing our ui intent over which will get called
            //when the notification is tapped.

            BitmapFactory.Options options = new BitmapFactory.Options();
            options.InSampleSize = 2;

            WebClient client = new WebClient();

            System.IO.Stream stream   = client.OpenRead(image);
            Bitmap           myBitmap = BitmapFactory.DecodeStream(stream, null, options);

            var notification = builder.SetContentIntent(PendingIntent.GetActivity(this, 0, uiIntent, 0))

                               .SetSmallIcon(Android.Resource.Drawable.SymActionEmail)
                               .SetTicker(title)
                               .SetContentTitle(title)
                               .SetContentText(desc)
                               .SetStyle(new NotificationCompat.BigPictureStyle().BigPicture(myBitmap))
                               .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.logo))

                               //Set the notification sound
                               .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                               //Auto cancel will remove the notification once the user touches it
                               .SetAutoCancel(true).Build();

            //Show the notification
            notificationManager.Notify(1, notification);
        }
예제 #23
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            try
            {
                if (isStarted)
                {
                    if (tempCount < Count)
                    {
                        tempCount = Count = 0;
                        prepairNotification();
                        TimeSpan runtime = DateTime.UtcNow.Subtract(startTime);
                    }
                }
                else
                {
                    startTime = DateTime.UtcNow;
                    timer     = new Timer(HandleTimerCallback, startTime, 0, TimerWait);
                    isStarted = true;

                    var contentIntent = PendingIntent.GetActivity(Android.App.Application.Context, 0, new Intent(Android.App.Application.Context, typeof(MainActivity)), 0);
                    var builder       = new NotificationCompat.Builder(Android.App.Application.Context)
                                        .SetContentIntent(contentIntent)
                                        .SetSmallIcon(Resource.Drawable.ic_launcher)
                                        .SetContentTitle("PostureApp")
                                        //.SetContentTitle(Resources.GetString(Resource.String.ApplicationName))
                                        .SetContentText("Service is running..")
                                        .SetOngoing(true)
                                        .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis());
                    var notification = builder.Build();
                    StartForeground(SERVICE_RUNNING_NOTIFICATION_ID, notification);
                }
            }
            catch (System.Exception e)
            {
                ExceptioHandler(e.Message, "OnStartCommand");
            }
            return(StartCommandResult.Sticky);
        }
        /// <summary>
        ///     Returns the <see cref="NotificationCompat" /> used as part of the foreground service.
        /// </summary>
        /// <returns>The <see cref="NotificationCompat" /> used as part of the foreground service.</returns>
        private Notification GetNotification()
        {
            var intent = new Intent(this, typeof(LocationUpdatesService));

            var text = Utils.GetLocationText(_location);

            // Extra to help us figure out if we arrived in onStartCommand via the notification or not.
            intent.PutExtra(ExtraStartedFromNotification, true);

            // The PendingIntent that leads to a call to onStartCommand() in this service.
            var servicePendingIntent = PendingIntent.GetService(this, 0, intent,
                                                                PendingIntentFlags.UpdateCurrent);

            // The PendingIntent to launch activity.
            var activityPendingIntent = PendingIntent.GetActivity(this, 0,
                                                                  new Intent(this, typeof(MainActivity)), 0);

            var builder = new NotificationCompat.Builder(this, ChannelId)
                          .AddAction(Resource.Drawable.ic_launch, GetString(Resource.String.launch_activity),
                                     activityPendingIntent)
                          .AddAction(Resource.Drawable.ic_cancel, GetString(Resource.String.remove_location_updates),
                                     servicePendingIntent)
                          .SetContentText(text)
                          .SetContentTitle(Utils.GetLocationTitle(this))
                          .SetOngoing(true)
                          .SetPriority((int)NotificationPriority.Low)
                          .SetSmallIcon(Resource.Mipmap.ic_launcher)
                          .SetTicker(text)
                          .SetWhen(JavaSystem.CurrentTimeMillis());

            // Set the Channel ID for Android O.
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                builder.SetChannelId(ChannelId);
            }

            return(builder.Build());
        }
        public int ScheduleNotification(string title, string message)
        {
            if (!channelInitialized)
            {
                CreateNotificationChannel();
            }

            messageId++;

            Intent intent = new Intent(AndroidApp.Context, typeof(MainActivity));

            intent.PutExtra(TitleKey, title);
            intent.PutExtra(MessageKey, message);
            intent.SetAction(MarkAsReadAction);

            PendingIntent pendingIntent = PendingIntent.GetActivity(AndroidApp.Context, pendingIntentId, intent, PendingIntentFlags.OneShot);

            PendingIntent intent2 = PendingIntent.GetActivity(AndroidApp.Context, pendingIntentId, intent, PendingIntentFlags.OneShot);

            // Setting SetPriority to PriorityHigh is step 1 of 2 to make notifications appear as Heads-Up
            // Notifications.
            // https://stackoverflow.com/questions/29949501/android-show-notification-with-a-popup-on-top-of-any-application
            NotificationCompat.Builder builder = new NotificationCompat.Builder(AndroidApp.Context, channelId)
                                                 .SetContentIntent(pendingIntent)
                                                 .SetContentTitle(title)
                                                 .SetContentText(message)
                                                 .SetLargeIcon(BitmapFactory.DecodeResource(AndroidApp.Context.Resources, Resource.Drawable.largeRooosterBlock))
                                                 .SetSmallIcon(Resource.Drawable.smallRoosterBlock)
                                                 .SetDefaults((int)NotificationDefaults.Sound | (int)NotificationDefaults.Vibrate)
                                                 .SetPriority(NotificationCompat.PriorityHigh)
                                                 .AddAction(Resource.Drawable.ic_mtrl_chip_checked_black, MarkAsReadAction, intent2);

            var notification = builder.Build();

            manager.Notify(messageId, notification);

            return(messageId);
        }
        public override void OnReceive(Context context, Intent intent)
        {
            if (!_channelInitialized)
            {
                CreateNotificationChannel();
            }

            _messageId++;

            Intent notifIntent = new Intent(Platform.AppContext, typeof(MainActivity));

            notifIntent.SetFlags(ActivityFlags.ClearTop);
            notifIntent.PutExtra(TitleKey, "Time for the daily reflection!");

            PendingIntent pendingIntent = PendingIntent.GetActivity(Platform.AppContext, PendingIntentId, notifIntent, PendingIntentFlags.UpdateCurrent);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(Platform.AppContext, ChannelId)
                                                 .SetContentIntent(pendingIntent)
                                                 .SetContentTitle("Time for the daily reflection!")
                                                 .SetSmallIcon(Resource.Drawable.notif_icon)
                                                 .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                                 .SetAutoCancel(true);

            var notification = builder.Build();

            _manager.Notify(_messageId, notification);

            var prefs = context.GetSharedPreferences(PreferenceConstants.PreferenceSharedName, FileCreationMode.Private);

            if (prefs == null)
            {
                return;
            }

            var timePref = prefs.GetLong(PreferenceConstants.NotificationTime, 0L);

            new NotificationService().ScheduleDailyNotification(DateTime.FromBinary(timePref));
        }
예제 #27
0
        private bool GetExpansionFiles()
        {
            bool result = false;

            // Build the intent that launches this activity.
            Intent launchIntent = this.Intent;
            var    intent       = new Intent(this, typeof(SuperSimpleActivity));

            intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
            intent.SetAction(launchIntent.Action);

            if (launchIntent.Categories != null)
            {
                foreach (string category in launchIntent.Categories)
                {
                    intent.AddCategory(category);
                }
            }

            // Build PendingIntent used to open this activity when user
            // taps the notification.
            PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent);

            // Request to start the download
            DownloadServiceRequirement startResult = DownloaderService.StartDownloadServiceIfRequired(this, pendingIntent, typeof(SampleDownloaderService));

            // The DownloaderService has started downloading the files,
            // show progress otherwise, the download is not needed so  we
            // fall through to starting the actual app.
            if (startResult != DownloadServiceRequirement.NoDownloadRequired)
            {
                this.downloaderServiceConnection = ClientMarshaller.CreateStub(this, typeof(SampleDownloaderService));

                result = true;
            }

            return(result);
        }
예제 #28
0
        // サービスの初期設定
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            // 設定情報の読み込み
            var setting       = new Setting();
            var documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            var filePath      = Path.Combine(documentsPath, "setting.json");

            if (File.Exists(filePath))
            {
                setting   = JsonConvert.DeserializeObject <Setting> (File.ReadAllText(filePath));
                threshold = setting.Threshold;
                url       = setting.Url;
            }

            // センサの設定
            _manager     = (SensorManager)Context.GetSystemService(Context.SensorService);
            _lightSensor = _manager.GetDefaultSensor(SensorType.Light);
            _manager.RegisterListener(this, _lightSensor, SensorDelay.Normal);

            // 通知使いまわし用設定
            Intent _intent = new Intent(Context, typeof(MainActivity));

            pendingIntent = PendingIntent.GetActivity(Context, 0, _intent, 0);
            this.startId  = startId;

            navigate = new Notification.Builder(Context)
                       .SetContentTitle("照度センサ")
                       .SetSmallIcon(Resource.Drawable.icon)
                       .SetContentText($"照度計測中です。{lux}")
                       .SetOngoing(true) //常駐
                       .SetContentIntent(pendingIntent)
                       .Build();

            StartForeground(this.startId, navigate);


            return(StartCommandResult.NotSticky);
        }
예제 #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
        private void DoNotify11(string title, string content) //Sem usar StackBuilder...
        {
            var context = Application.Context; //Equivalente à Android.App.Application.Context...

            Intent resultIntent = new Intent(context, typeof(MainActivity));
            resultIntent.SetFlags(ActivityFlags.SingleTop); //Setando ActivityFlags para SingleTop...

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

            var builder = new NotificationCompat.Builder(context)
                .SetContentTitle("11-" + title)
                .SetContentText(content)
                .SetContentIntent(pendingIntent)
                .SetSmallIcon(Resource.Drawable.icon);

            builder.SetOngoing(false);
            builder.SetAutoCancel(true);

            //var manager = NotificationManagerCompat.From(context);
            var manager = (NotificationManager)context.GetSystemService(Context.NotificationService);
            manager.Notify(11, builder.Build());
        }