简体   繁体   中英

Show Status Bar Notification with MonoDroid C#

How can I show a status bar notification with MonoDroid using C#?

Can someone give me an example?

Thanks.

You want to use Android.App.Notification and Android.App.NotificationManager , for example from LocalService.ShowNotification() :

// within some Android.Content.Context subclass (Activity, Service, etc.)
void ShowNotification ()
{
    IEnumerable<char> text = GetText (Resource.String.local_service_started);
    var notification = new Notification (Resource.Drawable.stat_sample, 
            text, 
            System.Environment.TickCount);
    PendingIntent contentIntent = PendingIntent.GetActivity (this, 0, 
            new Intent (this, typeof (LocalServiceActivities.Controller)), 
            0);
    notification.SetLatestEventInfo (this, 
            GetText (Resource.@string.local_service_label), 
            text, 
            contentIntent);
    var nm = (NotificationManager) GetSystemService (NotificationService);
    nm.Notify (Resource.String.local_service_started, notification);
}

您可以在下面的链接和喜欢的页面上看到更多信息: https : //www.facebook.com/pages/M%C3%A3-Ngu%E1%BB%93n/371039113001844

Try PushSharp: https://github.com/Redth/PushSharp

It worked great for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM