У меня есть 2 StatusBar Notification
в моем приложении. Эти уведомления появляются в приложении одновременно, и я вижу только последнее уведомление. И, если я нажму Button Clear
, они оба будут очищены. Как работать с более чем одним уведомлением в Android?
Второй вопрос - как отобразить текст notification
на в несколько строк . Я вижу только начало текста.
Вот мой код:
для первого уведомления:
private void setNotifiy() {
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence NotificationTicket = "You have a notification";
CharSequence contentTitle = "You are close to " + name_shop + "!!!";
CharSequence contentText = "So,you can go for shopping:)";
long when = System.currentTimeMillis();
Notification notification = new Notification(R.drawable.icon,
NotificationTicket, when);
Context context = getApplicationContext();
Intent notificationIntent = new Intent(this, ShopsOnMap.class);
System.out.println("DDDDd" + lat_choose + "!!!");
notificationIntent.putExtra("latshop", lat_choose);
notificationIntent.putExtra("longshop", long_choose);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
notificationManager.notify(NOTIFICATION_ID, notification);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
}
и для второго уведомления:
private void hey(String list) {
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence NotificationTicket = "Hey";
CharSequence contentTitle = "Shopping!!";
CharSequence contentText = "Today,you must go for shopping for your list ' "
+ list + "'" + "Don't forget!!!";
long when = System.currentTimeMillis();
Notification notification = new Notification(R.drawable.icon,
NotificationTicket, when);
Context context = getApplicationContext();
Intent notifyIntent = new Intent(context, Lists.class);
PendingIntent intent =
PendingIntent.getActivity(Lists.this, 0,
notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notification.setLatestEventInfo(context, contentTitle, contentText, intent);
notificationManager.notify(NOTIFICATION_ID, notification);
notificationManager.notify(NOTIFICATION_ID, notification);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
}