버전 8의 일부 실제 Android 장치에서 알림이 작동하지 않습니다. 9 가지 알림 설정이 활성화되었지만 정상적으로 작동합니다. 에뮬레이터. 알림을 트리거하도록 알람 관리자를 예약했습니다. 알림이있는 브로드 캐스트 수신기를 사용하는 시간 생성.
private void generateNotification(Context context, String message) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
createNotificationChannel(notificationManager);
RemoteViews view = new RemoteViews(context.getPackageName(), R.layout.notification_main);
view.setImageViewResource(R.id.ImageView1, R.drawable.tenkey_icon);
view.setTextViewText(R.id.title1, Utils.NOTIFICATION_TITLE);
view.setTextViewText(R.id.message1, message);
view.setTextViewText(R.id.time1, notificationTiming);
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.putExtra("content", message);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Notification.Builder builder=new Notification.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setOngoing(true)
.setContentIntent(PendingIntent.getActivity(context, 0, notificationIntent, 0))
.setContent(view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
builder.setChannelId(CHANNEL_ID);
}
Notification notification = builder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify((int)System.currentTimeMillis() % 1000000, notification);
}
private void createNotificationChannel(NotificationManager manager) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel serviceChannel = new NotificationChannel(
CHANNEL_ID,
"Shankaram",
NotificationManager.IMPORTANCE_DEFAULT
);
manager.createNotificationChannel(serviceChannel);
}
}
에뮬레이터에서 잘 작동하며 모든 실제 장치가 없습니다. 이 시점에서 임 테스트 및 디버그. 무엇이든 처리해야합니다. 안드로이드 파이의 알람 관리자? 제안하십시오