Android Notification with DecoratedCustomViewStyle

懵懂的女人 提交于 2019-12-04 18:06:44

It seems like this is an issue in the android support library. I tested it with the Notification Builder and it works like it should.

I used that guide: https://medium.com/exploring-android/android-n-introducing-upgraded-notifications-d4dd98a7ca92

I filed a bug for that issue at the official google issue tracker: https://issuetracker.google.com/issues/62475846

update

While this is not an actual bug on googles side, I think the implementation is not really ideal. The problem is, that the NotificationCompat of the v4 support lib is used, which does not work with the v7 decorator.

This usage happens because you cannot use the builder pattern the same way with v7 NotificationCompat.

import android.support.v7.app.NotificationCompat;

final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
notificationBuilder.setWhen(new Date().getTimeInMillis())
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle("title")
            .setContentText("text")
            .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
            .setContent(remoteViews);

update 2

Since the final release of the support library version 26.0.0 There is no need for using the v7 of the support library anymore. The DecoratedCustomViewStyle() is now available in the v4 version as well. So in your case you should do:

.setStyle(new NotificationCompat.DecoratedCustomViewStyle()) 

instead of

.setStyle(new android.support.v7.app.NotificationCompat.DecoratedCustomViewStyle())

Should now do the trick.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!