Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notification "setContentInfo" not show up

I'm using Android Studio. I wanna add message with number of notifications. Why when I run app there is no content info on the screen?

>

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);
}

I add the Notification Screeshot

like image 221
Full.Of.Life Avatar asked Nov 23 '16 00:11

Full.Of.Life


1 Answers

I am not sure about why the setContentInfo doesn't work. Probably cause you are trying in Nougat ? Anyways, according to the documentation, it is recommended to use setSubText(CharSequence) instead of setContentInfo(CharSequence info)

From Doc: This method was deprecated in API level 24. use setSubText(CharSequence) instead to set a text in the header. For legacy apps targeting a version below N this field will still show up, but the subtext will take precedence.

like image 67
San Avatar answered Oct 23 '22 08:10

San