Notification from a service

前端 未结 2 1029
长发绾君心
长发绾君心 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.

提交回复
热议问题