android Lollipop에 알림을 표시하는 문제가 있습니다. 응용 프로그램이 열리면 알림이 잘 표시되지만 응용 프로그램이 닫히면 표시되지 않습니다. 안드로이드의 4x 버전에서 모든 것이 제대로 작동합니다. 여기에 방법 내가이 문제라고 생각 그들에게android Lollipop. 알림이 작동하지 않습니다.
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void sendNotification(String body, String title, String badge) {
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("from_notify", true);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, Integer.valueOf(badge), intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle(title)
.setContentText(body)
.setPriority(Notification.PRIORITY_HIGH)
.setShowWhen(true)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
내 롤리팝 장치에서 코드를 확인한 결과 완벽하게 작동합니다. 활동과 방송 수신기에서 시작하는 두 경우 모두에서 테스트되었습니다. 활동이 종료되었는지 확인하기 위해 수신자는 BOOT 조치에 응답합니다. 문제는 다른 곳에서 발생합니다. 테스트 장치의 제조업체는 무엇입니까? 일부 제조업체는 일부 "앱 최적화"를 추가로 수행합니다. 예를 들어 Huawei의 경우 문자 그대로 강제로 앱을 중지하므로 방송 수신기가 작동하지 않으며 설명 된 동작과 일치합니다. '강제 정지'는 실행기에서 다시 시작될 때까지 앱을 사용 중지합니다. – mhenryk