Код: Выделить всё
Time limit already exhausted for foreground service type dataSync
https://developer.android.com/develop/b ... utобразное. 6-часовой предел < /strong>. < /p>
Согласно рекомендациям, чтобы избежать этой ошибки, мы должны позвонить
Код: Выделить всё
Service.stopSelf()Однако неясно, как реализовать это, когда служба переднего плана запускается через workmanager [/b].
Код: Выделить всё
public class MyCloudWorker extends Worker {
public Result doWork() {
...
ForegroundInfo foregroundInfo = createForegroundInfo(
0,
getString(R.string.auto_sync_with_cloud_in_progress)
);
setForegroundAsync(foregroundInfo);
...
}
@NonNull
private ForegroundInfo createForegroundInfo(int progress, String content) {
Assert(isForegroundServiceAllowable);
Context context = getApplicationContext();
String title = context.getString(R.string.auto_sync);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, createCloudNotificationChannel())
.setSmallIcon(R.drawable.ic_stat_name)
.setColorized(false)
.setTicker(title)
.setContentTitle(title)
.setContentText(content)
.setProgress(100, progress, false)
.setAutoCancel(false)
.setOngoing(true)
.setSound(null)
.setVibrate(null)
.setDefaults(Notification.DEFAULT_ALL & ~Notification.DEFAULT_LIGHTS & ~Notification.DEFAULT_VIBRATE & ~Notification.DEFAULT_SOUND);
Notification notification = builder.build();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
return new ForegroundInfo(
CLOUD_FOREGROUND_INTENT_SERVICE_ID,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
);
} else {
return new ForegroundInfo(
CLOUD_FOREGROUND_INTENT_SERVICE_ID,
notification
);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... when-using
Мобильная версия