Skip to content

Implement file download functionality in the Kotlin Bibledit app #1082

@teusbenschop

Description

@teusbenschop

The Bibledit app for Android used to have file download functionality.
It could download the exported USFM.zip and the like.

The app has been rewritten in Kotlin.
The download functionality still needs to be made to work in Kotlin too.

Here is the code for the file download functionality in Java

webview.setDownloadListener(new DownloadListener() {
    @Override
    public void onDownloadStart (String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
        DownloadManager.Request request = new DownloadManager.Request (Uri.parse (url));
        request.allowScanningByMediaScanner();
        // Notification once download is completed.
        request.setNotificationVisibility (DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        Uri uri = Uri.parse (url);
        String filename = uri.getLastPathSegment ();
        request.setDestinationInExternalPublicDir (Environment.DIRECTORY_DOWNLOADS, filename);
        DownloadManager dm = (DownloadManager) getSystemService (DOWNLOAD_SERVICE);
        dm.enqueue (request);
        // Notification that the file is being downloaded.
        Toast.makeText (getApplicationContext(), "Downloading file", Toast.LENGTH_LONG).show ();
    }
});

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions