android-components / mozilla.components.feature.downloads / DownloadsFeature

# DownloadsFeature

`class DownloadsFeature : SelectionAwareSessionObserver` (source)

Feature implementation for proving download functionality for the selected session. It will subscribe to the selected session and will listening for downloads.

### Constructors

<init> | `DownloadsFeature(applicationContext: Context, onNeedToRequestPermissions: OnNeedToRequestPermissions = { _, _ -> }, onDownloadCompleted: OnDownloadCompleted = { _, _ -> }, downloadManager: DownloadManager = DownloadManager(applicationContext, onDownloadCompleted), sessionManager: SessionManager, fragmentManager: FragmentManager? = null, dialog: DownloadDialogFragment = SimpleDownloadDialogFragment.newInstance())` Feature implementation for proving download functionality for the selected session. It will subscribe to the selected session and will listening for downloads.

### Properties

onDownloadCompleted | `var onDownloadCompleted: OnDownloadCompleted` a callback to be notified when a download is completed.
onNeedToRequestPermissions | `var onNeedToRequestPermissions: OnNeedToRequestPermissions` it will be call when you need to request permission, before a download can be performed.

### Inherited Properties

activeSession | `open var activeSession: Session?` the currently observed session

### Functions

onDownload | `fun onDownload(session: Session, download: Download): Boolean` Notifies to the DownloadManager that a new download must be processed.
onPermissionsGranted | `fun onPermissionsGranted(): Unit` Call this method to notify the feature download that the permissions where granted. If so it will automatically trigger the pending download.
start | `fun start(): Unit` Starts observing any download on the selected session and send it to the DownloadManager to be processed.
stop | `fun stop(): Unit` Stops observing any download on the selected session.

### Inherited Functions

observeFixed | `fun observeFixed(session: Session): Unit` Starts observing changes to the specified session.
observeSelected | `fun observeSelected(): Unit` Starts observing changes to the selected session (see SessionManager.selectedSession). If a different session is selected the observer will automatically be switched over and only notified of changes to the newly selected session.
onSessionSelected | `open fun onSessionSelected(session: Session): Unit` The selection has changed and the given session is now the selected session.