관리 메뉴

심재운 블로그

xamarin android 의 notification 을 구현하기 본문

모바일관련/Xamarin

xamarin android 의 notification 을 구현하기

재우니 2016. 11. 29. 09:51


xamarin android 의 notification 을 구현하기 위해서는 Notification.Build 객체를 사용해야 합니다.


using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace ExampleNotification
{
    [Activity(Label = "ExampleNotification", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
    
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

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

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

            button.Click += delegate 
            
            {
                Notification.Builder builder = new Notification.Builder(this)
                // title of notification
                .SetContentTitle("Developers Notification")
                //text of notification
                .SetContentText("Hello,This is my first notification")
                //icone of notification
                .SetSmallIcon(Resource.Drawable.Icon);


                //Build the notifications
                Notification notification = builder.Build();
                //Get the notification manager

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

                //publish the notification

                const int notificationId = 0;
                notificationManager.Notify(notificationId, notification);
            };
        }
    }
}





0 Comments
댓글쓰기 폼