The implementing service in the client app also needs to declare `dataSync` as `foregroundServiceType` in the manifest for
Android 14 compatibility. Adding the `FOREGROUND_SERVICE_DATA_SYNC` permission in the app manifest is not needed since it is declared in feature-downloads module.
Feature implementation for proving download functionality for the selected session.
```kotlin
//This will be called before starting each download in case you don't have the right permissions
// or if the user removed your permissions.
val onNeedToRequestPermissions = {
session: Session, download: Download ->
//request permission e.g (WRITE_EXTERNAL_STORAGE)
// After you get granted the permissions, remember to call downloadsFeature.onPermissionsGranted()
// to start downloading the pending download.
}
//This will be called after every download is completed.
val onDownloadCompleted = {
download: Download, downloadId: Long ->
//Show some UI to let user know the download was completed.
}
val downloadsFeature =
DownloadsFeature(context,
onNeedToRequestPermissions /*Optional*/,
onDownloadCompleted /*Optional*/,
fragmentManager /*Optional, if it is provided, before every download a dialog will be shown*/,
dialog /*Optional, if it is not provided a simple dialog will be shown before every download, with a positive button and negative button.*/,
sessionManager = sessionManager)
//Starts observing the selected session for new downloads and forward it to
// the download manager
downloadsFeature.start()
//Stop observing the selected session
downloadsFeature.stop()
```
### DownloadDialogFragment
This is general representation of a dialog meant to be used in collaboration with `DownloadsFeature`
to show a dialog before a download is triggered. If `SimpleDownloadDialogFragment` is not flexible enough for your use case you should inherit for this class.
```kotlin
class FocusDialogDownloadFragment : DownloadDialogFragment() {
/*Creating a customized the dialog*/
override fun onCreateDialog(bundle: Bundle?): AlertDialog {
//DownloadsFeature will add these metadata before calling show() on the dialog.
val fileName = arguments?.getString(KEY_FILE_NAME)
//Not used, just for the sake you can use this metadata
val url = arguments?.getString(KEY_URL)
val contentLength = arguments?.getString(KEY_CONTENT_LENGTH)
val builder = AlertDialog.Builder(requireContext())