Interface UnbluDownloadHandler


  • public interface UnbluDownloadHandler
    Handler for downloads. The download handler has to deal with the entire download process, requesting the file, handling storage permissions, storing the file at some location and so on.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      static UnbluDownloadHandler createExternalStorageDownloadHandler​(android.app.Application application)
      Creates a default implementation of UnbluDownloadHandler that stores downloaded files in the public downloads directory.
      void onDownloadStart​(com.unblu.sdk.core.internal.utils.IApplicationStateProvider applicationStateProvider, java.lang.String requestedUrl, java.lang.String userAgent, java.lang.String contentDisposition, java.lang.String mimeType, long contentLength, java.lang.String cookies)
      Triggered whenever a download is started.
      default void onDownloadStart​(com.unblu.sdk.core.internal.utils.IApplicationStateProvider applicationStateProvider, java.lang.String requestedUrl, java.lang.String userAgent, java.lang.String contentDisposition, java.lang.String mimeType, long contentLength, java.lang.String cookies, java.lang.String oAuthToken)
      Triggered whenever a download is started.
      default void onWebViewDestroy()
      Called whenever the webView is destroyed.
      default void onWebViewInitialize()
      Called whenever the webView is initialized.
    • Method Detail

      • createExternalStorageDownloadHandler

        static UnbluDownloadHandler createExternalStorageDownloadHandler​(android.app.Application application)
        Creates a default implementation of UnbluDownloadHandler that stores downloaded files in the public downloads directory.
        Parameters:
        application - The application instance
        Returns:
        The default implementation using SharedPreferences
      • onDownloadStart

        void onDownloadStart​(com.unblu.sdk.core.internal.utils.IApplicationStateProvider applicationStateProvider,
                             java.lang.String requestedUrl,
                             java.lang.String userAgent,
                             java.lang.String contentDisposition,
                             java.lang.String mimeType,
                             long contentLength,
                             java.lang.String cookies)
        Triggered whenever a download is started. Except for the cookies, this matches the DownloadListener of WebView.

        If you need the MIME type and content disposition but they're missing, you can use an additional HEAD request to retrieve them from the server.

        Parameters:
        applicationStateProvider - The applicationStateProvider to check for the active activity
        requestedUrl - The full URL to the content that should be downloaded
        userAgent - The user agent for the download
        contentDisposition - The Content-Disposition HTTP header, if present
        mimeType - The MIME type of the content, as reported by the server
        cookies - The cookies used inside the WebView that are relevant for this request. For example, you may need to add cookies to the request to gain access to the file.
        contentLength - The Content-Length HTTP header
      • onDownloadStart

        default void onDownloadStart​(com.unblu.sdk.core.internal.utils.IApplicationStateProvider applicationStateProvider,
                                     java.lang.String requestedUrl,
                                     java.lang.String userAgent,
                                     java.lang.String contentDisposition,
                                     java.lang.String mimeType,
                                     long contentLength,
                                     java.lang.String cookies,
                                     java.lang.String oAuthToken)
        Triggered whenever a download is started. Except for the cookies, this matches the DownloadListener of WebViews. Use this method if you set an OAuth token in the current UnbluClientConfiguration.

        If you need the MIME type and content disposition but they're missing, you can use an additional HEAD request to retrieve them from the server.

        Parameters:
        applicationStateProvider - The applicationStateProvider to check for the active activity
        requestedUrl - The full URL to the content that should be downloaded
        userAgent - the user agent to be used for the download.
        contentDisposition - Content-disposition http header, if present.
        mimeType - The mimeType of the content reported by the server.
        cookies - The cookies used inside the WebView which are relevant for this request. They may have to be added to the request to have access to the file.
        contentLength - Content-Length
        oAuthToken - optional oAuthToken,
      • onWebViewInitialize

        default void onWebViewInitialize()
        Called whenever the webView is initialized. This happens during the initialization of the SDK.
        The method can be used to do some initial setup, for example, to listen to the Android https://developer.android.com/reference/android/app/DownloadManager[`DownloadManager`^].
      • onWebViewDestroy

        default void onWebViewDestroy()
        Called whenever the webView is destroyed. This happens when the SDK is deinitialized.
        The method can be used to do some cleanup, for example of listeners on the Android https://developer.android.com/reference/android/app/DownloadManager[`DownloadManager`^].