daily notification

Hi,
I want to push notification at specific time on daily in my my app. I use xamarin and build a cross platform app. Please help me?
Thanks.

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    If you need a local notification you can take a look there

    https://github.com/edsnider/Xamarin.Plugins/blob/master/README.md

    There is a notifyTime parameter

  • oflu1071oflu1071 TRMember

    I want you to repeat notification every day. What do i need to do for it?

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    Notifier.Current.Show("You've got mail", "You have 793 unread messages!");
    Notifier.Current.Show("Good morning", "Time to get up!", 1, DateTime.Now.AddDays(1);
    Notifier.Current.Cancel(1);

    Maybe the GoodMorning one

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    Without cancel

  • oflu1071oflu1071 TRMember

    this one is add day to now time. So notification to be display at tomorrow. but not display two days later. I want to displaying every day of week.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I think it continues to notify till you cancel it

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    The Notifier plugin doesn't support repeating notifications. I don't know of a cross-platform plugin that does. You'll need to implement the notifications natively on each platform and use a dependency service to call the implementation from your PCL.

  • LearnEverythingLearnEverything USMember ✭✭

    2016 I used this code and notify daily, I dont know for latest android

    Manifest

     <uses-permission android:name="android.permission.WAKE_LOCK" />
      <uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
      <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
    

    AlarmReceiver

    using Android.App;
    using Android.Content;
    using Android.Graphics;
    using Android.Support.V4.App;
    
    namespace XamarinAndroid.Core
    {
        [BroadcastReceiver]
        [IntentFilter(new string[] { "android.intent.action.BOOT_COMPLETED" }, Priority = (int)IntentFilterPriority.LowPriority)]
        public class AlarmReceiver : BroadcastReceiver
        {
            public override void OnReceive(Context context, Intent intent)
            {
    
                ////var message = intent.GetStringExtra("message");
                ////var title = intent.GetStringExtra("title");
    
    
                string message = "This is a sample message";//Replace with your notification message
                string title = "this is a sample title";//Replace with your notification Title
    
                var notIntent = new Intent(context, typeof(MainActivity));
                var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);
                var manager = NotificationManagerCompat.From(context);
                var style = new Notification.BigTextStyle();
                style.BigText(message);
                int resourceId;
                resourceId = Resource.Drawable.NotiIcon;
                //    resourceId = Resource.Drawable.icon;
                var wearableExtender = new Notification.WearableExtender().SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId));
                //Generate a notification with just short text and small icon
                var builder = new Notification.Builder(context, "channel_id")
                .SetContentIntent(contentIntent)
                .SetSmallIcon(Resource.Drawable.NotiIcon)
                .SetContentTitle(title)
                .SetContentText(message)
                .SetStyle(style)
                .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                .SetAutoCancel(true)
                .Extend(wearableExtender);
                var notification = builder.Build();
                manager.Notify(0, notification);
    
            }
    
        }
    }
    

    Start Daily Notification

    static Toast repeating;
            static long halfday = 43200000;
            //long fifteenSeconds = 5 * 1000;
            public static void StartDailyNotification(Context context, Type alarmReceiverType)
            {
                // When the alarm goes off, we want to broadcast an Intent to our
                // BroadcastReceiver.  Here we make an Intent with an explicit class
                // name to have our own receiver (which has been published in
                // AndroidManifest.xml) instantiated and called, and then create an
                // IntentSender to have the intent executed as a broadcast.
                // Note that unlike above, this IntentSender is configured to
                // allow itself to be sent multiple times.
                var intent = new Intent(context, alarmReceiverType);
                var source = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent);
    
                // Schedule the alarm!
                var am = (AlarmManager)context.GetSystemService(Context.AlarmService);
                am.SetRepeating(AlarmType.ElapsedRealtimeWakeup,
                        SystemClock.ElapsedRealtime() + halfday,
                        halfday,
                        source);          
            }
        }
    
Sign In or Register to comment.