2017-05-11 4 views
0

브로드 캐스트 리시버에 알림이 포함 된 알림을 보내고 브로드 캐스트 리시버가 알림을 실행합니다. 7.0 이전에는 알림이 수신시 의도에 표시되고 7.0에서는 알림이 누락되었습니다.안드로이드 7.0에서 인 텐트로 알림이 누락 됨

다음은 알림을 생성하는 코드입니다.

public static void scheduleNotification(Context context, String message, long delay, 
             MainDisplay.NotificationType type) { 
    Notification.Builder builder = new Notification.Builder(context).setSmallIcon(
      R.drawable.ic_stat_o) 
                    .setContentTitle(
                      "Title") 
                    .setContentText(
                      message) 
                    .setStyle(
                      new Notification 
                        .BigTextStyle() 
                        .bigText(
                          message)); 

    final Intent notificationIntent = generateNotificationIntent(context); 
    notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, builder.build()); 
    notificationIntent.putExtra(TYPE_KEY, type); 

    final PendingIntent pendingIntent = generatePendingIntent(context, notificationIntent); 

    final long futureInMillis = SystemClock.elapsedRealtime() + delay; 
    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(
      Context.ALARM_SERVICE); 
    alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent); 
} 

여기에 보류중인 의도 코드가 있습니다.

public static PendingIntent generatePendingIntent(Context context, Intent notificationIntent) { 
    return PendingIntent.getBroadcast(context, 0, notificationIntent, 
             PendingIntent 
               .FLAG_UPDATE_CURRENT); 
} 

여기 코드가 있습니다.

public void onReceive(final Context context, Intent intent) { 
    final NotificationManager 
      notificationManager = (NotificationManager) context.getSystemService(
      Context.NOTIFICATION_SERVICE); 

    final Notification notification = intent.getParcelableExtra(NOTIFICATION); 
    final int id = intent.getIntExtra(NOTIFICATION_ID, 0); 
    notificationManager.notify(id, notification); 

아이디어가 있으십니까? 감사!

+0

'generatePendingIntent()'의 구현은 무엇입니까? – CommonsWare

+0

@CommonsWare가 방금 추가되었습니다. –

+0

OK, 괜찮아 보입니다. 다른 간단한 추가 기능을 추가하여 사용했는지 확인해 보셨습니까? IOW, 일반적으로 엑스트라 나 비교적 펑키 한 것에 문제가 있습니까? – CommonsWare

답변

0

내가 보낸 일련 번호가있는 열거 형도 누락 된 것으로 나타났습니다. 너무 큰 의도 트랜잭션과 관련하여 7.0에서 변경된 사항을 알았지 만, 예외없이 여기에 적용되는 방법을 잘 모르겠습니다. 던져졌다. onReceive에서 알림을 구성하는 데 필요한 정보를 보내기로했습니다.