Notification from a service

前端 未结 2 1030
长发绾君心
长发绾君心 2021-01-22 19:10

I\'m trying to display a simple notification when a C2DM message is received. Services provide to UI but still run on the main thread. I\'ve seen people claim you can create and

相关标签:
2条回答
  • 2021-01-22 19:14

    First, the exception is thrown because you create a notification which has no view object referenced to it (contentView attribute is set to null) . You have to call setLatestEventInfo before showing the notification.

    Second, the constructor you're using is deprecated. Please use the class Notification.Builder for creating notifications. If you support Android < API level 11, you can use the class NotificationCompat.Builder from the support library.

    Third, yes it is possible to create notifications from a running service.

    0 讨论(0)
  • 2021-01-22 19:21

    You should read the Notification documentation. Content View is required if you don't called the setLatestEventInfo() method.

    0 讨论(0)
提交回复
热议问题