2017-05-24 8 views
1

알림 일단 알림이 생성되었지만 다른 알림은 마지막 알림을 만들고 업데이트하지 않습니다. 나는 새 알림을새로운 알림 전경 안드로이드 서비스를 만들지 않음

전화 알림 방법 싶어 : 서비스에서

private void NotificationLoop() { 

    // one notification 
     G.HANDLER.postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       populateNotification(1, "task id : " + 1, 20); 
      } 
     }, 2000); 
// two notification 
     G.HANDLER.postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       populateNotification(2, "task id : " + 2, 40); 
      } 
     }, 2000); 
// three notification 
     G.HANDLER.postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       populateNotification(3, "task id : " + 3, 80); 
      } 
     }, 3000); 


    } 

populateNotification 내 방법 :

private void populateNotification(int id, String title, int percent) { 

     Notification notification; 
     Intent CancelIntent = new Intent(this, ServiceDownload.class); 
     CancelIntent.setAction(Constant.ACTION.CANCEL_DOANLOAD_ACTION); 
     CancelIntent.putExtra("ID", id); 
     PendingIntent CCancelIntent = PendingIntent.getService(this, 0, CancelIntent, 0); 

     Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); 

     Intent notificationIntent = new Intent(this, MainActivity.class); 
     notificationIntent.setAction(Intent.ACTION_MAIN); 
     notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

     notification = new NotificationCompat.Builder(this) 
       .setContentTitle(title) 
       .setTicker(title) 
       .setContentText(title) 
       .setSmallIcon(R.mipmap.ic_launcher) 
       .setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false)) 
       .setContentIntent(pendingIntent) 
       .setAutoCancel(false) 
       .setOngoing(false) 
       .addAction(android.R.drawable.ic_menu_close_clear_cancel, this.getResources().getString(R.string.Cancel), CCancelIntent) 
       .setProgress(100, percent, false) 
       .setStyle((new NotificationCompat.BigTextStyle().bigText(title))) 
       .build(); 
     startForeground(id, notification); 
    } 
+0

시작합니다. 동일한 서비스입니다. 하나의 서비스가 startForeground에 대해 하나의 알림 만 사용할 수있는 것처럼 보입니다. startForeground 대신 NotificationManager를 사용하여 두 번째 및 세 번째 알림 표시 –

+0

감사합니다. –

답변

0

전경 서비스는 하나의 통지를 가지고있다.

그래서 startForeground(id, notification);으로 전화하면 방금 교체합니다.

당신은 당신의 문제를 해결하기 위해 많은 선택의 여지가 그나마

  1. 새 알림 만들기는하지
  2. 정지 전경 서비스를 서비스를 다시 시작합니다, 그래서 알림 정확히 새로운 될 것입니다 관련 그러나이 그 사용자는 새로운 알림이며 업데이트 된 이전 알림이 아니라는 것을 에 알리지 않습니다.
  3. 새 알림으로 새 전경 서비스를 시작하십시오.