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

时间:2014-01-22 22:36:08

标签: c# android notifications xamarin android-notifications

(这是使用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);

1 个答案:

答案 0 :(得分:5)

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

来自documentation

通知对象必须包含以下内容

  • 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());

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