Skip to content

Commit aee0e9f

Browse files
committed
update document
1 parent 72f9907 commit aee0e9f

File tree

6 files changed

+147
-74
lines changed

6 files changed

+147
-74
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.4.0 - 12.01.2020
2+
3+
* migrate to Android v2 embedding.
4+
15
## 1.3.4 - 21.12.2019
26

37
* fix bug stuck in Flutter v12.13

README.md

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -179,78 +179,9 @@ private func registerPlugins(registry: FlutterPluginRegistry) {
179179

180180
### Required configuration:
181181

182-
* Configure `Application`:
183-
184-
Java:
185-
```java
186-
// MyApplication.java (create this file if it doesn't exist in your project)
187-
188-
import io.flutter.app.FlutterApplication;
189-
import io.flutter.plugin.common.PluginRegistry;
190-
import io.flutter.plugins.GeneratedPluginRegistrant;
191-
import vn.hunghd.flutterdownloader.FlutterDownloaderPlugin;
192-
193-
public class MyApplication extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
194-
@Override
195-
public void registerWith(PluginRegistry registry) {
196-
//
197-
// Integration note:
198-
//
199-
// In Flutter, in order to work in background isolate, plugins need to register with
200-
// a special instance of `FlutterEngine` that serves for background execution only.
201-
// Hence, all (and only) plugins that require background execution feature need to
202-
// call `registerWith` in this method.
203-
//
204-
// The default `GeneratedPluginRegistrant` will call `registerWith` of all plugins
205-
// integrated in your application. Hence, if you are using `FlutterDownloaderPlugin`
206-
// along with other plugins that need UI manipulation, you should register
207-
// `FlutterDownloaderPlugin` and any 'background' plugins explicitly like this:
208-
//
209-
// FlutterDownloaderPlugin.registerWith(registry.registrarFor("vn.hunghd.flutterdownloader.FlutterDownloaderPlugin"));
210-
//
211-
GeneratedPluginRegistrant.registerWith(registry);
212-
}
213-
}
214-
```
215-
216-
Or Kotlin:
217-
```kotlin
218-
// MyApplication.kt (create this file if it doesn't exist in your project)
219-
220-
import io.flutter.app.FlutterApplication
221-
import io.flutter.plugin.common.PluginRegistry
222-
import io.flutter.plugins.GeneratedPluginRegistrant
223-
import vn.hunghd.flutterdownloader.FlutterDownloaderPlugin
224-
225-
internal class MyApplication : FlutterApplication(), PluginRegistry.PluginRegistrantCallback {
226-
override fun registerWith(registry: PluginRegistry) {
227-
//
228-
// Integration note:
229-
//
230-
// In Flutter, in order to work in background isolate, plugins need to register with
231-
// a special instance of `FlutterEngine` that serves for background execution only.
232-
// Hence, all (and only) plugins that require background execution feature need to
233-
// call `registerWith` in this method.
234-
//
235-
// The default `GeneratedPluginRegistrant` will call `registerWith` of all plugins
236-
// integrated in your application. Hence, if you are using `FlutterDownloaderPlugin`
237-
// along with other plugins that need UI manipulation, you should register
238-
// `FlutterDownloaderPlugin` and any 'background' plugins explicitly like this:
239-
//
240-
// FlutterDownloaderPlugin.registerWith(registry.registrarFor("vn.hunghd.flutterdownloader.FlutterDownloaderPlugin"))
241-
//
242-
GeneratedPluginRegistrant.registerWith(registry)
243-
}
244-
}
245-
```
182+
* If your project is running on Flutter versions prior v1.12, have a look at [this document](android_integration_note.md) to configure your Android project.
246183

247-
And update `AndroidManifest.xml`
248-
```xml
249-
<!-- AndroidManifest.xml -->
250-
<application
251-
android:name=".MyApplication"
252-
....>
253-
```
184+
* From Flutter v1.12 with Android v2 embedding there's no additional configurations required to work with background isolation in Android.
254185

255186
* In order to handle click action on notification to open the downloaded file on Android, you need to add some additional configurations. Add the following codes to your `AndroidManifest.xml`:
256187

@@ -270,8 +201,6 @@ And update `AndroidManifest.xml`
270201
- You have to save your downloaded files in external storage (where the other applications have permission to read your files)
271202
- 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)
272203

273-
274-
275204
### Optional configuration:
276205

277206
* **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`:
@@ -322,6 +251,7 @@ import 'package:flutter_downloader/flutter_downloader.dart';
322251
#### Initialize
323252

324253
````dart
254+
WidgetsFlutterBinding.ensureInitialized();
325255
await FlutterDownloader.initialize();
326256
````
327257

android_integration_note.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
## Android integration
2+
3+
### Required configuration:
4+
5+
* Configure `Application`:
6+
7+
Java:
8+
```java
9+
// MyApplication.java (create this file if it doesn't exist in your project)
10+
11+
import io.flutter.app.FlutterApplication;
12+
import io.flutter.plugin.common.PluginRegistry;
13+
import io.flutter.plugins.GeneratedPluginRegistrant;
14+
import vn.hunghd.flutterdownloader.FlutterDownloaderPlugin;
15+
16+
public class MyApplication extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
17+
@Override
18+
public void registerWith(PluginRegistry registry) {
19+
//
20+
// Integration note:
21+
//
22+
// In Flutter, in order to work in background isolate, plugins need to register with
23+
// a special instance of `FlutterEngine` that serves for background execution only.
24+
// Hence, all (and only) plugins that require background execution feature need to
25+
// call `registerWith` in this method.
26+
//
27+
// The default `GeneratedPluginRegistrant` will call `registerWith` of all plugins
28+
// integrated in your application. Hence, if you are using `FlutterDownloaderPlugin`
29+
// along with other plugins that need UI manipulation, you should register
30+
// `FlutterDownloaderPlugin` and any 'background' plugins explicitly like this:
31+
//
32+
// FlutterDownloaderPlugin.registerWith(registry.registrarFor("vn.hunghd.flutterdownloader.FlutterDownloaderPlugin"));
33+
//
34+
GeneratedPluginRegistrant.registerWith(registry);
35+
}
36+
}
37+
```
38+
39+
Or Kotlin:
40+
```kotlin
41+
// MyApplication.kt (create this file if it doesn't exist in your project)
42+
43+
import io.flutter.app.FlutterApplication
44+
import io.flutter.plugin.common.PluginRegistry
45+
import io.flutter.plugins.GeneratedPluginRegistrant
46+
import vn.hunghd.flutterdownloader.FlutterDownloaderPlugin
47+
48+
internal class MyApplication : FlutterApplication(), PluginRegistry.PluginRegistrantCallback {
49+
override fun registerWith(registry: PluginRegistry) {
50+
//
51+
// Integration note:
52+
//
53+
// In Flutter, in order to work in background isolate, plugins need to register with
54+
// a special instance of `FlutterEngine` that serves for background execution only.
55+
// Hence, all (and only) plugins that require background execution feature need to
56+
// call `registerWith` in this method.
57+
//
58+
// The default `GeneratedPluginRegistrant` will call `registerWith` of all plugins
59+
// integrated in your application. Hence, if you are using `FlutterDownloaderPlugin`
60+
// along with other plugins that need UI manipulation, you should register
61+
// `FlutterDownloaderPlugin` and any 'background' plugins explicitly like this:
62+
//
63+
// FlutterDownloaderPlugin.registerWith(registry.registrarFor("vn.hunghd.flutterdownloader.FlutterDownloaderPlugin"))
64+
//
65+
GeneratedPluginRegistrant.registerWith(registry)
66+
}
67+
}
68+
```
69+
70+
And update `AndroidManifest.xml`
71+
```xml
72+
<!-- AndroidManifest.xml -->
73+
<application
74+
android:name=".MyApplication"
75+
....>
76+
```
77+
78+
* In order to handle click action on notification to open the downloaded file on Android, you need to add some additional configurations. Add the following codes to your `AndroidManifest.xml`:
79+
80+
````xml
81+
<provider
82+
android:name="vn.hunghd.flutterdownloader.DownloadedFileProvider"
83+
android:authorities="${applicationId}.flutter_downloader.provider"
84+
android:exported="false"
85+
android:grantUriPermissions="true">
86+
<meta-data
87+
android:name="android.support.FILE_PROVIDER_PATHS"
88+
android:resource="@xml/provider_paths"/>
89+
</provider>
90+
````
91+
92+
**Note:**
93+
- You have to save your downloaded files in external storage (where the other applications have permission to read your files)
94+
- 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)
95+
96+
97+
98+
### Optional configuration:
99+
100+
* **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`:
101+
102+
````xml
103+
<provider
104+
android:name="androidx.work.impl.WorkManagerInitializer"
105+
android:authorities="${applicationId}.workmanager-init"
106+
android:enabled="false"
107+
android:exported="false" />
108+
109+
<provider
110+
android:name="vn.hunghd.flutterdownloader.FlutterDownloaderInitializer"
111+
android:authorities="${applicationId}.flutter-downloader-init"
112+
android:exported="false">
113+
<!-- changes this number to configure the maximum number of concurrent tasks -->
114+
<meta-data
115+
android:name="vn.hunghd.flutterdownloader.MAX_CONCURRENT_TASKS"
116+
android:value="5" />
117+
</provider>
118+
````
119+
120+
* **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])
121+
122+
````xml
123+
<string name="flutter_downloader_notification_started">Download started</string>
124+
<string name="flutter_downloader_notification_in_progress">Download in progress</string>
125+
<string name="flutter_downloader_notification_canceled">Download canceled</string>
126+
<string name="flutter_downloader_notification_failed">Download failed</string>
127+
<string name="flutter_downloader_notification_complete">Download complete</string>
128+
<string name="flutter_downloader_notification_paused">Download paused</string>
129+
````
130+
131+
* **PackageInstaller:** in order to open APK files, your application needs `REQUEST_INSTALL_PACKAGES` permission. Add following codes in your `AndroidManifest.xml`:
132+
133+
````xml
134+
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
135+
````

example/android/app/app.iml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,8 @@
153153
<orderEntry type="module" module-name="flutter_downloader" />
154154
<orderEntry type="module" module-name="permission_handler" />
155155
<orderEntry type="module" module-name="path_provider" />
156+
<orderEntry type="module" module-name="flutter_downloader" />
157+
<orderEntry type="module" module-name="permission_handler" />
158+
<orderEntry type="module" module-name="path_provider" />
156159
</component>
157160
</module>

example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:permission_handler/permission_handler.dart';
99
import 'dart:io';
1010

1111
void main() async {
12+
WidgetsFlutterBinding.ensureInitialized();
1213
await FlutterDownloader.initialize();
1314

1415
runApp(new MyApp());

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_downloader
22
description: A plugin for creating and managing download tasks. Supports iOS and Android.
3-
version: 1.3.4
3+
version: 1.4.0
44
authors:
55
- Flutter Community <[email protected]>
66
- Hung Duy Ha <[email protected]>

0 commit comments

Comments
 (0)