我正在使用 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);
}
最佳答案
我不确定为什么 setContentInfo
不起作用。可能是因为您正在尝试牛轧糖?无论如何,根据文档,建议使用 setSubText(CharSequence)
而不是 setContentInfo(CharSequence info)
From Doc : 此方法在 API 级别 24 中已弃用。请改用 setSubText(CharSequence) 在 header 中设置文本。对于以低于 N 的版本为目标的旧版应用程序,此字段仍会显示,但潜台词将优先。
关于android - 通知 "setContentInfo"未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40753885/