在Android应用中使用通知是否需要权限?

Wil*_*son 2 c# notifications android android-notifications xamarin

(这是使用C#/ Xamarin)

是否需要使用NotificationManager.Notify().没有通知,但应该是.这是我的代码:

int myId = 123123;
Notification nt = new Notification(Resource.Drawable.Icon,"Stuff");
NotificationManager not = (NotificationManager)GetSystemService(Context.NotificationService);
not.Notify (myId, nt);
Run Code Online (Sandbox Code Playgroud)

Bar*_*icz 5

不,发布通知不需要权限.

来自文档:

Notification对象必须包含以下内容:

  • 一个小图标,由setSmallIcon()设置
  • 标题,由setContentTitle()设置
  • 详细文本,由setContentText()设置

也许你错过了其中一个,因为你的构造函数只有2个参数?

在Xamarin教程中,他们使用Notification.Builder对象发布通知.也许那会奏效.

NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
    .SetContentTitle("Button Clicked")
    .SetSmallIcon(Resource.Drawable.ic_stat_button_click)
    .SetContentText(String.Format("The button has been clicked {0} times.", _count));

    // Obtain a reference to the NotificationManager
    NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
    notificationManager.Notify(ButtonClickNotificationId, builder.Build());
Run Code Online (Sandbox Code Playgroud)

这是教程的链接:http: //docs.xamarin.com/guides/cross-platform/application_fundamentals/notifications/android/local_notifications_in_android/