Я сохранил WorkManager UUID
, преобразованный в String
в базе данных Realm.
Вот код -
Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();
Data inputData = new Data.Builder().putString("downloadUrl", downloadUrl).
putString("destinationFolder", destinationFolder).
putInt("suraNumber", Integer.parseInt(suraNumber)).
putString("fileName", fileName).
putBoolean("downloadFileTypeBangla", downloadFileTypeBangla).
putBoolean("downloadFileTypeArabic", downloadFileTypeArabic).
putBoolean("downloadFileTypeArabicWithBangla", downloadFileTypeArabicWithBangla).build();
OneTimeWorkRequest downloadWork = new OneTimeWorkRequest.Builder(DownloadWorker.class).setConstraints(constraints).setInputData(inputData).build();
WorkManager.getInstance().enqueue(downloadWork);
Sura sura = dbOperations.getSuraById(Integer.parseInt(suraNumber));
if(sura != null){
dbOperations.updateSura(sura, Integer.parseInt(suraNumber), sura.getBnAudioDownloadStatus(), sura.getArAudioDownloadStatus(), 1);
realm.beginTransaction();
DownloadStatusModel downloadStatusModel = new DownloadStatusModel();
downloadStatusModel.setId(new RealmCommonService(realm).newId(DownloadStatusModel.class));
downloadStatusModel.setDownloadFileType("ArabicWithBangla");
downloadStatusModel.setActiveStatus(true);
downloadStatusModel.setDownloadDate(new Date());
downloadStatusModel.setDownloadedSuraNo(sura.getSuraNo());
downloadStatusModel.setDownloadFileSize(sura.getArBnAudioFileSize());
downloadStatusModel.setDownloadReferenceId(downloadWork.getId().toString());
downloadStatusModel.setDownloadedSuraNameBangla(sura.getSuraNameBangla());
downloadStatusModel.setDownloadStatus(1);
realm.copyToRealm(downloadStatusModel);
realm.commitTransaction();
}
Сейчас я пытаюсь отменить Work
, используя эту строку кода, но не сработало.
WorkManager.getInstance().cancelWorkById(UUID.fromString(downloadStatusModel.getDownloadReferenceId()));
Буду признателен за любую помощь
Спасибо