K
K
Kirill Zhuk2014-05-10 16:43:54
Android
Kirill Zhuk, 2014-05-10 16:43:54

How can I make all notifications from a certain application appear under one icon in the Status bar?

How can I make all notifications from a certain application appear under one icon in the Status bar (i.e. similar events add up to one notification), and on the icon itself there would be a number with the number of these notifications? I tried like this, but, unfortunately, the number does not even appear, and notifications are replaced one with another:

import android.app.Activity;  
import android.app.Notification;  
import android.app.NotificationManager;  
import android.app.PendingIntent;  
import android.content.Intent;  
import android.os.Bundle;  
public class Mondayremind extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int notifID = getIntent().getExtras().getInt("NotifID");
    Intent i = new Intent();
    i.putExtra("NotifID", notifID);

    PendingIntent detailsIntent = PendingIntent.getActivity(this, 0, i, 0);

    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Notification notif = new Notification(R.drawable.iconcapng,
            "Приложение", System.currentTimeMillis());
    Bundle extras = getIntent().getExtras();
    String str = extras.getString("StringNotif");
    CharSequence from = "Напоминание";
    CharSequence message = str;
    notif.setLatestEventInfo(this, from, message, detailsIntent);

    notif.vibrate = new long[] { 100, 250, 100, 500 };
    notif.flags |= Notification.FLAG_AUTO_CANCEL;
    notif.number += 1;
    notif.flags |= Notification.FLAG_NO_CLEAR;
    notif.defaults |= Notification.DEFAULT_LIGHTS;
    notif.defaults |= Notification.DEFAULT_SOUND;
    notif.flags |= Notification.FLAG_SHOW_LIGHTS;

    nm.notify(notifID, notif);

    finish();
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
belozerow, 2014-05-10
@belozerow

I did not know about the existence of number, but judging by the code you always have it == 1.
In the documentation:

For example, before HONEYCOMB, this number was superimposed over the icon in the status bar. Starting with HONEYCOMB, the template used by Notification.Builder has displayed the number in the expanded notification view. If the number is 0 or negative, it is never shown.

Those. after Android 3.0, the number will not be shown over the notification icon, but will be displayed in the expanded notification.
You already do this by specifying the same id for all notifications.
And yes, some strange way - to launch the activity, show the notification, and then kill the activity. Not to mention the hardcoded strings and empty click intent.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question