Android Custom Notification doesn't Display

后端 未结 1 1859
眼角桃花
眼角桃花 2021-02-11 02:36

I\'m having trouble getting a notification with a custom layout to display. If I use the following (old) code:

notification = new Notification();
notification.ic         


        
相关标签:
1条回答
  • 2021-02-11 03:16

    A status bar notification requires all of the following:

    • An icon for the status bar
    • A title and message, unless you define a custom notification layout
    • A PendingIntent, to be fired when the notification is selected

    from Status Bar Notifications - Creating Notifications

    You don't specify an icon, which means your notification is not valid.

    (But yes, it's bad on the framework side that there is no proper error message/exception for this case)


    Edit: Just tested this through and I can confirm the "invisible" notification from the comment on Android 2.2. It works on 2.3.3., seems like you stumbled over a bug that has been fixed in the meantime.

    The problematic line is the following for me:

    contentView.setViewVisibility(R.id.pgStatus, View.GONE);
    

    If I comment that out, everything works. It also works when I add android:visibility="gone" to the ProgressBar in the XML layout, which has basically the same effect. But as soon as I call setViewVisibility() on the bar, everything breaks apart.

    So I'd recommend the workaround from the bugtracker comments, wrap the ProgressBar into a LinearLayout and change the visibility of that instead.

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