bezzad / Downloader

Fast, cross-platform and reliable multipart downloader with asynchronous progress events for .NET applications.
MIT License
1.25k stars 193 forks source link

Using in .Net Maui App #138

Closed NileshPhalke123 closed 1 year ago

NileshPhalke123 commented 1 year ago

Can this Downloader be used in .net maui app so it can run on native platforms like android, ios, etc.

bezzad commented 1 year ago

Yes, it is possible to use the Downloader library in a .NET MAUI app to download files on native platforms like Android, iOS, etc.

Since .NET MAUI is a cross-platform framework, you can create a single codebase that targets multiple platforms. To use the Downloader library in a .NET MAUI app, you would need to add the library as a NuGet package to your project. Once you have added the package, you can use the library in your code to download files.

Here's an example of how you can use the library in your code:

using Downloader;

string file = @"Your_Path\fileName.zip";
string url = @"https://file-examples.com/fileName.zip";

var downloader = new DownloadService(downloadOpt);
await downloader.DownloadFileTaskAsync(url, file);

downloader.DownloadProgressChanged += (sender, args) =>
{
    // Update progress bar or UI with progress information
};

downloader.DownloadFileCompleted+= (sender, e) =>
{
    if (e.Cancelled)
    {
        // File download cancelled by user
    }
    else if (e.Error != null)
    {
       // Handle error
    }
    else
    {
       // File downloaded successfully
    }
};

Note that you will need to request the necessary permissions to access the internet and write to external storage (if applicable) on each platform.