Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 38 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ The following steps require to open your `ios` project in Xcode.

1. Enable background mode.

<img width="512" src="https://github.com/hnvn/flutter_downloader/blob/master/screenshot/enable_background_mode.png?raw=true"/>
<img width="512"
src="https://github.com/hnvn/flutter_downloader/blob/master/screenshot/enable_background_mode.png?raw=true"/>

2. Add `sqlite` library.

Expand Down Expand Up @@ -110,7 +111,7 @@ private func registerPlugins(registry: FlutterPluginRegistry) {
- **Support HTTP request:** if you want to download file with HTTP request, you
need to disable Apple Transport Security (ATS) feature. There're two options:

1. Disable ATS for a specific domain only: (add following codes to your
1. Disable ATS for a specific domain only: (add the following code to your
`Info.plist` file)

```xml
Expand All @@ -134,7 +135,7 @@ private func registerPlugins(registry: FlutterPluginRegistry) {
</dict>
```

2. Completely disable ATS: (add following codes to your `Info.plist` file)
2. Completely disable ATS. Add the following to your `Info.plist` file)

```xml
<key>NSAppTransportSecurity</key>
Expand All @@ -146,7 +147,7 @@ private func registerPlugins(registry: FlutterPluginRegistry) {
- **Configure maximum number of concurrent tasks:** the plugin allows 3 download
tasks running at a moment by default (if you enqueue more than 3 tasks,
there're only 3 tasks running, other tasks are put in pending state). You can
change this number by adding following codes to your `Info.plist` file.
change this number by adding the following code to your `Info.plist` file.

```xml
<!-- changes this number to configure the maximum number of concurrent tasks -->
Expand All @@ -172,12 +173,14 @@ private func registerPlugins(registry: FlutterPluginRegistry) {

## Android integration

There's no additional configurations required on Android.
You don't have to do anything extra to make the plugin work on Android.

In order to handle click action on notification to open the downloaded file on
Android, you need to add some additional configurations.
There are although a few optional settings you might want to configure.

Add the following to `AndroidManifest.xml`:
### Open downloaded file from notification

To make tapping on notification open the downloaded file on Android, add the
following code to `AndroidManifest.xml`:

```xml
<provider
Expand All @@ -191,20 +194,19 @@ Add the following to `AndroidManifest.xml`:
</provider>
```

**Note:**
**Notes**

- You have to save your downloaded files in external storage (where the other
applications have permission to read your files)
- The downloaded files are only able to be opened if your device has at least an
application that can read these file types (mp3, pdf, etc)
- The downloaded files are only able to be opened if your device has at least
one application that can read these file types (mp3, pdf, etc.)

### Optional configuration:
### Configure maximum number of concurrent download tasks

- **Configure maximum number of concurrent tasks:** the plugin depends on
`WorkManager` library and `WorkManager` depends on the number of available
processor to configure the maximum number of tasks running at a moment. You
can setup a fixed number for this configuration by adding following codes to
your `AndroidManifest.xml`:
The plugin depends on `WorkManager` library and `WorkManager` depends on the
number of available processor to configure the maximum number of tasks running
at a moment. You can setup a fixed number for this configuration by adding the
following code to your `AndroidManifest.xml`:

```xml
<!-- Begin FlutterDownloader customization -->
Expand Down Expand Up @@ -233,9 +235,10 @@ Add the following to `AndroidManifest.xml`:
<!-- End FlutterDownloader customization -->
```

- **Localize notification messages:** you can localize notification messages of
download progress by localizing following messages. (you can find the detail
of string localization in Android in this [link][4])
### Localize strings in notifications

You can localize texts in download progress notifications by localizing
following messages.

```xml
<string name="flutter_downloader_notification_started">Download started</string>
Expand All @@ -246,9 +249,13 @@ Add the following to `AndroidManifest.xml`:
<string name="flutter_downloader_notification_paused">Download paused</string>
```

- **PackageInstaller:** in order to open APK files, your application needs
`REQUEST_INSTALL_PACKAGES` permission. Add the following code in your
`AndroidManifest.xml`:
You can learn more about localization on Android [here][4]).

### Install .apk files

To open and install `.apk` files, your application needs
`REQUEST_INSTALL_PACKAGES` permission. Add the following in your
`AndroidManifest.xml`:

```xml
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
Expand Down Expand Up @@ -437,12 +444,16 @@ plugin is missing some feature.

Pull request are also very welcome!

[fluttercommunity_badge]: https://fluttercommunity.dev/_github/header/flutter_downloader
[fluttercommunity_badge]:
https://fluttercommunity.dev/_github/header/flutter_downloader
[fluttercommunity_link]: https://github.com/fluttercommunity/community
[pub_badge]: https://img.shields.io/pub/v/flutter_downloader.svg
[pub_link]: https://pub.dartlang.org/packages/flutter_downloader
[work_manager]: https://developer.android.com/topic/libraries/architecture/workmanager
[url_session_download_task]: https://developer.apple.com/documentation/foundation/nsurlsessiondownloadtask?language=objc
[android_9_cleartext_traffic]: https://medium.com/@son.rommer/fix-cleartext-traffic-error-in-android-9-pie-2f4e9e2235e6
[work_manager]:
https://developer.android.com/topic/libraries/architecture/workmanager
[url_session_download_task]:
https://developer.apple.com/documentation/foundation/nsurlsessiondownloadtask?language=objc
[android_9_cleartext_traffic]:
https://medium.com/@son.rommer/fix-cleartext-traffic-error-in-android-9-pie-2f4e9e2235e6
[3]: https://medium.com/@guerrix/info-plist-localization-ad5daaea732a
[4]: https://developer.android.com/training/basics/supporting-devices/languages
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class DownloadWorker extends Worker implements MethodChannel.MethodCallHa
private static final int STEP_UPDATE = 5;

private static final AtomicBoolean isolateStarted = new AtomicBoolean(false);
private static final ArrayDeque<List> isolateQueue = new ArrayDeque<>();
private static final ArrayDeque<List<Object>> isolateQueue = new ArrayDeque<>();
private static FlutterEngine backgroundFlutterEngine;

private final Pattern charsetPattern = Pattern.compile("(?i)\\bcharset=\\s*\"?([^\\s;\"]*)");
Expand All @@ -114,12 +114,7 @@ public DownloadWorker(@NonNull final Context context,
@NonNull WorkerParameters params) {
super(context, params);

new Handler(context.getMainLooper()).post(new Runnable() {
@Override
public void run() {
startBackgroundIsolate(context);
}
});
new Handler(context.getMainLooper()).post(() -> startBackgroundIsolate(context));
}

private void startBackgroundIsolate(Context context) {
Expand Down Expand Up @@ -150,7 +145,7 @@ private void startBackgroundIsolate(Context context) {
}

@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
public void onMethodCall(MethodCall call, @NonNull MethodChannel.Result result) {
if (call.method.equals("didInitializeDispatcher")) {
synchronized (isolateStarted) {
while (!isolateQueue.isEmpty()) {
Expand Down Expand Up @@ -819,12 +814,7 @@ public interface CallbackUri {
void invoke(Uri uri);
}

final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {

public boolean verify(String hostname, SSLSession session) {
return true;
}
};
final static HostnameVerifier DO_NOT_VERIFY = (hostname, session) -> true;

/**
* Trust every server - dont check for any certificate
Expand All @@ -838,11 +828,11 @@ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}

public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
public void checkClientTrusted(X509Certificate[] chain, String authType) {
Log.i(TAG, "checkClientTrusted");
}

public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
public void checkServerTrusted(X509Certificate[] chain, String authType) {
Log.i(TAG, "checkServerTrusted");
}
} };
Expand Down
5 changes: 5 additions & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include: package:leancode_lint/analysis_options.yaml

linter:
rules:
avoid_print: false
6 changes: 0 additions & 6 deletions example/android/app/src/debug/AndroidManifest.xml

This file was deleted.

7 changes: 1 addition & 6 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
xmlns:tools="http://schemas.android.com/tools" package="vn.hunghd.flutter_downloader_example">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"/>
Expand Down
6 changes: 0 additions & 6 deletions example/android/app/src/profile/AndroidManifest.xml

This file was deleted.

18 changes: 0 additions & 18 deletions example/example.iml

This file was deleted.

17 changes: 0 additions & 17 deletions example/flutter_downloader_example.iml

This file was deleted.

27 changes: 0 additions & 27 deletions example/flutter_downloader_example_android.iml

This file was deleted.

Loading