아주 오래된 오류 하나 문의합니다.
포그라운드서비스 호출 관련 오류입니다.
오류내용은 다음과 같아요
Fatal Exception: android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground()
매니페스트에 아래권한 추가되어 있구요.
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
*ManageService.class 서비스 클래스 코드
@Override
public void onCreate() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int NOTIFICATION_ID = 2020;
String CHANNEL_ID = "channel_bar";
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
context.getResources().getString(R.string.content_txt_43),
NotificationManager.IMPORTANCE_NONE);
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
Notification notification = new androidx.core.app.NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("")
.setAutoCancel(false)
.setShowWhen(false)
.setSmallIcon(getPngImage(level))
.setContentIntent(pendingIntent)
.setContent(remoteViews)
.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
startForeground(NOTIFICATION_ID, notification);
}
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return Service.START_STICKY;
}
* 메인 액티비티 클래스에서 시작하는 코드
Intent intent = new Intent(MainActivity.this, ManageService.class);
boolean isRunning = isServiceRunningCheck();
if (!isRunning) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent);
} else {
startService(intent);
}
}
테스트 폰이 4개 정도(오레오 버전 이상) 있는데.. 모두 정상 동작하며 오류가 발생하지않아요.
혹시 해결법을 아시는 분 계신가요?
구글링하여도 딱히 해결법이 나오지 않네요.
제가 유추하는 바로는 휴대폰 자체적으로 백그라운드서비스 제한에 걸려서 시작를 못해서 발생되는 오류가 아닐까 라는 의심만 하고 있네요.