2014-01-22 57 views
2

(這是使用C#/ Xamarin)是否需要在Android應用程序中使用通知的權限?

是否有使用NotificationManager.Notify()所需的權限。沒有通知出現,但它應該是。這裏是我的代碼:

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

回答

4

不,不需要權限發佈通知。

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/

相關問題