우선 배운 적 없이 독학으로 개발중입니다 그래서 기본적인 부분을 놓치고 있는지도 모르겠네요 ㅠ
// 이게 오레오 버전부터 사용되는 NOTIFICATION 기본 생성 방식인듯?
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// SDK 버전 호출하여 오레오(API 26)버전 이상일 경우
if (Build.VERSION.SDK_INT >= 26){
Log.e("오레오", "targetSDK 오레오");
NotificationChannel mChannel = new NotificationChannel("seungje","seungje", NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(mChannel);
builder = new NotificationCompat.Builder(this, mChannel.getId());
} else {
builder = new NotificationCompat.Builder(this);
}
builder.setAutoCancel(true)
.setSmallIcon(R.mipmap.ic_launcher)
.setDefaults(NotificationCompat.DEFAULT_VIBRATE)
.setContentTitle("타이틀")
.setContentIntent(pendingIntent);
notificationManager.notify(0, builder.build());
이러한 방식으로 notification을 만들었는데요 잠금화면 커버?를 만들고 싶어서 task kill로도 죽지 않는 서비스를 만들고 싶습니다
main에서 안드로이드 o에서 지원하는 startForegroundService로 ScreenService.java를 호출하게 되고 onStartCommand에 위 소스를 구현했습니다
제가 아는 부분은 startForegroundService로 서비스를 호출하면 5초 이내로 startforeground 를 선언해야 한다고 하는데,
startForeground(1, new Notification());
이런식으로 선언하면 에러가 발생합니다 제 생각에는 오레오 부터 채널? 을 만들어서 넣어줘야하는데, 그게 없어서 에러가 나는 것 같아요 ㅠㅠ
오레오 버전에서 startForeground 사용 예제 정도만 알려주시면 제가 잘 활용해보겠습니다ㅠㅠ