1

간단한 Android 애플리케이션을 만들었으며 푸시 알림과 통합되었습니다. 푸시 알림이 제대로 작동하지만 이제는 목록에 표시된 알림 수를 제한하려고합니다 (최대 5 개). 사용자가 6 번째를 얻으면 가장 오래된 것을 제거하고 싶습니다. 나는 웹을 통과하지만이 일을 구현할 방법을 찾을 수 없습니다.Android : 알림 표시 줄의 알림 수를 제한합니다.

  1. 이 시나리오를 구현할 수 있습니까?

내 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()); 
} 
+0

http://stackoverflow.com/questions/14171018/how-to-limit-the-number-of -notifications-being-by-a-service-in-android –

답변

0

그래, 우리는이를 구현할 수 이것이다. 6 번째 알림이 도착하면 로컬에서 알림 ID를 저장하고 첫 번째 ID를 삭제했습니다 (대기열을 사용할 수 있도록 대기열을 사용할 수 있습니다).