Skip to content

Compatibility of Android O Service

冉天华 edited this page Aug 3, 2018 · 1 revision

In Android O, we cannot start a background service during app is in background. If we want to start a service, it must be a foreground service. You can refer to here to know more details.

In version 1.7.5, we handle this case and you can config your own notification in this way:

final String channelId = "Test";
Notification notification = new NotificationCompat.Builder(this, channelId)
        .setSmallIcon(R.mipmap.ic_launcher)
        .setContentText("Downloading")
        .setContentTitle("FileDownloader Demo")
        .build();
ForegroundServiceConfig config = new ForegroundServiceConfig.Builder()
        .notification(notification)
        .notificationChannelId(channelId)
        .notificationChannelName("name")
        .needRecreateChannelId(true) // if your channel id is created before, you can ignore this configuration and you don't need to provide channel id and channel name
        .notificationId(R.mipmap.ic_launcher)    
        .build();
FileDownloader.setupOnApplicationOnCreate(this)
        .foregroundServiceConfig(config)
        .commit();

If you don't custom notification, the default notification is like this: