Я создал простую андроид-приложение и интегрировал ее с push-уведомлениями. Push-уведомления работают правильно, но теперь я хочу ограничить количество уведомлений, отображаемых в списке (максимум 5). когда пользователь получает 6-й, вы хотите удалить самую старую. я прохожу через Интернет, но я не могу найти способ реализовать эту вещь.Android: ограничить количество уведомлений в панели уведомлений
- Возможно ли реализовать этот сценарий?
это мой GCM Намерение сервис,
@Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
// The getMessageType() intent parameter must be the intent you received
// in your BroadcastReceiver.
String messageType = gcm.getMessageType(intent);
// Log.e(getPackageName(), messageType);
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
// sendNotification("Send error: " + extras.toString());
} else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
// sendNotification("Deleted messages on server: " +
// extras.toString());
// If it's a regular GCM message, do some work.
} else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
// Post notification of received message.
// newms = extras.getString("message").toString();
sendNotification(extras.getString("title"), extras.getString("id"));
;
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
private void sendNotification(String title, String id) {
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("title", title);
intent.putExtra("id", id);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.pqr)
.setContentTitle(getString(R.string.app_name)).setSound(uri).setStyle(new NotificationCompat.BigTextStyle().bigText(title))
.setContentText(title);
mBuilder.setDefaults(Notification.DEFAULT_ALL);
mBuilder.setAutoCancel(true);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(Integer.parseInt(id), mBuilder.build());
}
http://stackoverflow.com/questions/14171018/how-to-limit-the-number-of -notifications благополучие посланного-на-услуга-в-андроид –