안드로이드 8.0이후 부터 Notification에 채널ID를 추가해줘야한다고 해줬는데
안드로이드 8.0에서는 알림 유형 - 사용 안함 으로 되어 있고, 8.1은 알림 유형 - 소리 없음 으로 되어
8.0은 안 뜨고, 8.1은 뜹니다.
채널ID를 부여했는데도 왜 이렇죠??
커스텀 NOTIFICATION을 사용하였습니다.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
startMyOwnForeground();
}else {
startForeground(NOTIFICATION_ID, notification);
}
@TargetApi(Build.VERSION_CODES.O)
private void startMyOwnForeground(){
String NOTIFICATION_CHANNEL_ID = "company.sensor.valuesensor";
String channelName = "Service";
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
chan.setLightColor(Color.BLUE);
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
assert manager != null;
manager.createNotificationChannel(chan);
Intent notiintent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notiintent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent fininotiintent = new Intent(this, ServiceClass.class);
fininotiintent.putExtra("finish_all", "finish_all");
PendingIntent pfinishIntent = PendingIntent.getService(this, 0, fininotiintent,
PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification;
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_layout);
contentView.setImageViewResource(R.id.image, R.mipmap.ic_launcher);
contentView.setTextViewText(R.id.title, getResources().getString(R.string.noti_title));
contentView.setTextViewText(R.id.text, getResources().getString(R.string.noti_content));
contentView.setOnClickPendingIntent(R.id.finish_button, pfinishIntent);
notification = new Notification.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContent(contentView)
.setContentIntent(pendingIntent)
.setPriority(Notification.PRIORITY_MAX)
.setOngoing(true)
.setChannelId(NOTIFICATION_CHANNEL_ID)
.build();
startForeground(NOTIFICATION_ID1, notification);
}