c# - 状态栏通知 xamarin native android

标签 c# xamarin mobile xamarin.android

它不会给出任何错误或显示通知。

NotificationCompat.Builder builder = new NotificationCompat.Builder(Activity)
            .SetAutoCancel(true)
            .SetContentIntent(resultPendingIntent)
            .SetContentTitle("My Notifications")
            .SetContentText(" Work dammit -_-");
            NotificationManager notificationManager = (NotificationManager)Activity.GetSystemService(Android.Content.Context.NotificationService);
            notificationManager.Notify(ButtonClickNotification, builder.Build());

最佳答案

我找到了解决问题的方法。

I got my solution from here

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(Resource.Drawable.Icon, title);
            //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);
        }

关于c# - 状态栏通知 xamarin native android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50600538/

相关文章:

c# - 日期的字符串格式

c# - C#中using语句的用法

android - 为什么找不到Android SDK?

mobile - Outlook Mobile 加载项 list 示例?

mobile - WAMPServer,手机访问服务器

c# - 有谁知道我在哪里可以找到通用 Windows 专用网络(客户端和服务器)代码示例?

c# - 使用 Microsoft.ML 和 DetectIidSpike 了解尖峰

visual-studio - 在 Visual Studio 中使用 F# 的 Xamarin Forms 应用程序

ios - Mono 框架或 Mono 运行时是 Xamarin IOS ipa 包的一部分吗?

css - 我如何使用 flexbox 缩小图像?