2013-12-13 3 views
2

클릭시 내 알림을 설정하려면 어떻게해야합니까?클릭시 알림을 설정하는 방법은 무엇입니까?

나는 autoCancel(true) 설정 한하지만 내 코드

을 작동하지 않습니다,

Notification n = new Notification.Builder(this) 
       .setContentTitle("Update for you") 
       .setContentText("Please click here to see the update information") 
       .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), 
                  R.drawable.ic_launcher)) 
       .setSmallIcon(R.drawable.ic_launcher) 
       .setContentIntent(pList) 
       .setAutoCancel(true) 
       .addAction(R.drawable.ic_read, "Read", pRead) 
       .addAction(R.drawable.ic_list, "All Updates", pList) 
       .build(); 

NotificationManager notificationManager = 
         (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

notificationManager.notify(0, n); 

답변

1

사용이 Notification.BuilderFLAG_AUTO_CANCEL

n.flags |= Notification.FLAG_AUTO_CANCEL; 
+0

감사합니다, 나는 그것을 테스트거야하지만 난 그렇게하지를 추가 NotificationCompat.Builder 클래스 형태로도 주문 가능합니다 때때로 내 알림이 표시되는 이유를 알고 있지만 때로는 그렇지 않습니다. ( – user2790880

3

setAutoCancel()는 아마도 API (11)에 도입하여 최소 버전은 API 11보다 낮습니다.

setAutoCancel()는 지원 라이브러리 (참)

Notification n = new NotificationCompat.Builder(this) 
       .setContentTitle("Update for you") 
       .setContentText("Please click here to see the update information") 
       .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), 
                  R.drawable.ic_launcher)) 
       .setSmallIcon(R.drawable.ic_launcher) 
       .setContentIntent(pList) 
       .setAutoCancel(true) 
       .addAction(R.drawable.ic_read, "Read", pRead) 
       .addAction(R.drawable.ic_list, "All Updates", pList) 
       .build(); 
+0

답변을 주셔서 감사합니다. 내 'android : minSdkVersion'은 13 – user2790880

+0

btw입니다. Notification과 NotificationCompat의 차이점은 무엇입니까? NotificationCompat를 사용해야합니까? – user2790880

+0

아니요, 여전히 알림을 표시하기 위해 '알림'을 사용하고 있습니다. 'NotificationCompat'는 하위 레벨 호환 방식으로 API 레벨 4 이후에 소개 된'Notification '의 기능에 액세스하기위한 헬퍼 클래스입니다. – Geros

1

SetAutoCancel 답변에 대한

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
      // .setLargeIcon(image)/*Notification icon image*/ 
      .setSmallIcon(R.drawable.ic_notification) 
      .setContentTitle("Quiz Tap") 
      .setContentText(messageBody) 
      /*.setStyle(new NotificationCompat.BigPictureStyle() 
        .bigPicture(image))*//*Notification with Image*/ 
      **.setAutoCancel(true)** 
      .setSound(defaultSoundUri) 
      .setContentIntent(pendingIntent); 
+0

이것은 저에게 효과적입니다. –

관련 문제