2012-12-26 1 views
0

내 응용 프로그램에서 로컬 알림을 사용하고 있습니다.Android에서 알림 클릭에 아무런 영향을주지 않습니다.

showNotification(this, "Title1", "Message One", 1); 
    showNotification(this, "Title2", "Message Two", 2); 
    showNotification(this, "Title3", "Message Three", 3); 
    showNotification(this, "Title4", "Message Four", 4); 


public static void showNotification(Context con, String title, 
     String message, int id) { 


    NotificationManager manager = (NotificationManager) con 
      .getSystemService(Context.NOTIFICATION_SERVICE); 

    Notification note = new Notification(R.drawable.ic_noti_logo,title, System.currentTimeMillis()); 

    Intent notificationIntent = new Intent(con,Result.class); 
    notificationIntent.putExtra("Message", message); 
    notificationIntent.putExtra("NotiId", id); 

    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
      | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

    PendingIntent pi = PendingIntent.getActivity(con, 0, 
      notificationIntent, PendingIntent.FLAG_ONE_SHOT); 

    note.setLatestEventInfo(con, title, message, pi); 

    note.defaults |= Notification.DEFAULT_ALL; 
    note.flags |= Notification.FLAG_AUTO_CANCEL; 
    manager.notify(id, note); 
} 

Resut.java에

message = getIntent().getStringExtra("Message"); 
    notiId = getIntent().getIntExtra("NotiId", 0); 

    showAlert(message,notiId); 

private void showAlert(String msg, int id) { 
    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setMessage(msg).setCancelable(false) 
      .setPositiveButton("OK", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
       // finish(); 
        cancelNotification(Result.this,id); 
       } 
      }); 
    AlertDialog alert = builder.create(); 
    alert.show(); 
} 

public static void cancelNotification(Context con, int id) { 

    NotificationManager manager = (NotificationManager) con 
      .getSystemService(Context.NOTIFICATION_SERVICE); 
    manager.cancel(id); 
} 

내 문제는 내가 알림 표시 줄에 4 알림 메시지를 받고, 그리고 난 그들 중 하나가 내가 Result 활동에 리디렉션하고 클릭하고 때 그것은 단지 hapens이다 두 번째 클릭했을 때 효과가 없습니다. 도와주세요.

답변

1

문제는 4 개의 알림이 동일한 인 텐트를 참조하기 때문에 동일한 PendingIntent을 공유한다는 것입니다 (Intent.filterEquals()에 대한 문서는 별개라고 생각되는 것으로 설명하고, 의도, 동작, 데이터, 클래스, 유형 또는 카테고리 모두에서 다름) 추가 정보는 인 텐트가 동등한 지 여부를 결정할 때 특별히 고려되지 않습니다). 또한 PendingIntent을 한 번만 사용할 수 있다는 것을 보장하는 PendingIntent.FLAG_ONE_SHOT을 사용하고 있습니다.

관련 문제