This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyWorker(context: Context, parameters: WorkerParameters) : | |
Worker(context, parameters) { | |
override fun doWork(): Result { | |
setForeground(createForegroundInfo()) | |
downloadSomething() | |
return Result.success() | |
} | |
private fun createForegroundInfo(): ForegroundInfo { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun scheduleForegroundTask() { | |
val foregroundTaskInfo = foregroundTaskInfo { | |
id = TASK_ID | |
networkType = NetworkType.Any | |
persisted = true | |
minLatencyMillis = TimeUnit.HOURS.toMillis(12) | |
timeoutMillis = TimeUnit.MINUTES.toMillis(1) | |
retryData = RetryData(retryPolicy = RetryPolicy.Exponential, initialBackoff = 4000) | |
} | |
ForegroundTasksSchedulerWrapper().scheduleForegroundTask( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReposForegroundService : ForegroundTaskService() { | |
override fun getNotification(): Notification { | |
// create channel | |
val channelId = resources.getString(R.string.my_channel) | |
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { | |
val notificationChannel = NotificationChannel(channelId, channelId, NotificationManager.IMPORTANCE_DEFAULT) | |
notificationChannel.setSound(null, null) | |
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | |
notificationManager.createNotificationChannel(notificationChannel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Settings( | |
val volume: Int, | |
val userName: String, | |
val fontSize: Float, | |
val privacyEnabled: Boolean | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"a":55, | |
"b":"rotem matityahu", | |
"c":30.0, | |
"d":true | |
} |