通知中的“setContentInfo”未显示出来

6
我正在使用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);
}

我添加了通知截图

(说明:此句是关于在IT技术中添加通知截图的内容)
1个回答

12

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

来自文档此方法已在API级别24中弃用。请改用setSubText(CharSequence) 在标题中设置文本。对于针对低于N版本的遗留应用程序,此字段仍将显示,但子文本将优先。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接