android - 通知 "setContentInfo"未显示

标签 android notifications

我正在使用 Android Studio。我想添加带有通知数量的消息。为什么当我运行应用程序时,屏幕上没有内容信息?

>

private int i = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

public void notyfikacja(View view) {

    Intent intent = new Intent(this, SecondActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder
            .setSmallIcon(android.R.drawable.arrow_up_float)
            .setContentInfo("You have"+  ++i + "messages" )
            .setContentText("ContentText")
            .setContentTitle("ContentTitle")
            .setAutoCancel(true)
            .setContentIntent(pendingIntent);

    Notification notification = builder.build();
    NotificationManagerCompat.from(this).notify(0, notification);
}

我添加了 Notification Screeshot

最佳答案

我不确定为什么 setContentInfo 不起作用。可能是因为您正在尝试牛轧糖?无论如何,根据文档,建议使用 setSubText(CharSequence) 而不是 setContentInfo(CharSequence info)

From Doc : 此方法在 API 级别 24 中已弃用。请改用 setSubText(CharSequence) 在 header 中设置文本。对于以低于 N 的版本为目标的旧版应用程序,此字段仍会显示,但潜台词将优先。

关于android - 通知 "setContentInfo"未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40753885/

相关文章:

Android通知 Intent 自行清除

javascript - 通知权限总是被拒绝

ruby-on-rails - 在 Rails 上扩展 Flash 消息的功能?自动隐藏、嵌入链接 ?关闭按钮?

Android非矩形按钮,如何处理?

java - 使用相机检测真实物体。使用相机寻找真实物体的可能性

android - 如何读/写 bool 首选项

android - Corona SDK 显示多行通知

notifications - Chef 'notifies :action, ' 资源', :before' work at all as it should?

android - 如何区分Android上的语音通话和视频通话?

java - 如何在改造的GET中使用多个@Path参数