Skip to content

Commit a445b9b

Browse files
committed
Released version 1.3.6
2 parents a126338 + 2364364 commit a445b9b

File tree

3 files changed

+60
-41
lines changed

3 files changed

+60
-41
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
## Changes
22

3-
### 1.3.3
3+
### 1.3.6
4+
5+
* Fixed bug [#77](https://github.com/SimonSimCity/Xamarin-CrossDownloadManager/issues/77): [Android] Download are cancelled with no reason
6+
7+
### 1.3.5
8+
9+
* *changes in documentation*
10+
11+
### 1.3.4
412

513
* Add possibility to prevent files from showing up in download manager
614

15+
### 1.3.3
16+
17+
* *no changes*
18+
719
### 1.3.2
820

921
* Fixed bug [#69](https://github.com/SimonSimCity/Xamarin-CrossDownloadManager/issues/69): Using PathNameForDownloadedFile: Android suffixes filename by '-1' if file already exists

DownloadManager/Plugin.DownloadManager.Android/DownloadManagerImplementation.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,24 @@ void StartDownloadWatcher ()
127127
// Create a runnable, restarting itself to update every file in the queue
128128
_downloadWatcherHandlerRunnable = new Java.Lang.Runnable (() => {
129129
var downloads = Queue.Cast<DownloadFileImplementation>().ToList();
130-
LoopOnDownloads (cursor => {
131-
int id = cursor.GetInt(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnId));
132-
var downloadFile = downloads.FirstOrDefault(f => f.Id == id);
133130

134-
if (downloadFile != null) {
135-
downloads.Remove(downloadFile);
136-
UpdateFileProperties(cursor, downloadFile);
137-
}
138-
});
139-
140-
// All downloads still in this list are not listed in the native donload-manager of Android. Mark them as canceled.
141131
foreach (var file in downloads) {
142-
Abort(file);
132+
var query = new Android.App.DownloadManager.Query();
133+
query.SetFilterById(file.Id);
134+
135+
try {
136+
using (var cursor = _downloadManager.InvokeQuery(query)) {
137+
if (cursor != null && cursor.MoveToNext()) {
138+
UpdateFileProperties(cursor, file);
139+
} else {
140+
// This file is not listed in the native download manager anymore. Let's mark it as canceled.
141+
Abort(file);
142+
}
143+
cursor?.Close();
144+
}
145+
} catch (Android.Database.Sqlite.SQLiteException) {
146+
// I lately got an exception that the database was unaccessible ...
147+
}
143148
}
144149

145150
_downloadWatcherHandler.PostDelayed (_downloadWatcherHandlerRunnable, 1000);

README.md

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The CrossDownloadManager is a plugin that helps you downloading files in the background.
44

5-
### Build Status:
5+
### Build Status:
66
![GitHub tag](https://img.shields.io/github/tag/SimonSimCity/xamarin-crossdownloadmanager.svg)
77
[![NuGet](https://img.shields.io/nuget/v/Xam.Plugins.DownloadManager.svg?label=NuGet)](https://www.nuget.org/packages/Xam.Plugins.DownloadManager/)
88

@@ -23,26 +23,26 @@ Add the nuget package to your cross-platform project and to every platform speci
2323
#### iOS
2424

2525
_AppDelegate.cs_
26-
```
27-
/**
28-
* Save the completion-handler we get when the app opens from the background.
29-
* This method informs iOS that the app has finished all internal processing and can sleep again.
30-
*/
31-
public override void HandleEventsForBackgroundUrl(UIApplication application, string sessionIdentifier, Action completionHandler)
32-
{
33-
CrossDownloadManager.BackgroundSessionCompletionHandler = completionHandler;
34-
}
26+
```csharp
27+
/**
28+
* Save the completion-handler we get when the app opens from the background.
29+
* This method informs iOS that the app has finished all internal processing and can sleep again.
30+
*/
31+
public override void HandleEventsForBackgroundUrl(UIApplication application, string sessionIdentifier, Action completionHandler)
32+
{
33+
CrossDownloadManager.BackgroundSessionCompletionHandler = completionHandler;
34+
}
3535
```
3636

3737
As of iOS 9, your URL must be secured or you have to add the domain to the list of exceptions. See [https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS9.html#//apple_ref/doc/uid/TP40016198-SW14](https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS9.html#//apple_ref/doc/uid/TP40016198-SW14)
3838

3939
### Start downloading
4040

4141
You can now start a download by adding the following code:
42-
```
43-
var downloadManager = CrossDownloadManager.Current;
44-
var file = downloadManager.CreateDownloadFile(url);
45-
downloadManager.Start(file);
42+
```csharp
43+
var downloadManager = CrossDownloadManager.Current;
44+
var file = downloadManager.CreateDownloadFile(url);
45+
downloadManager.Start(file);
4646
```
4747

4848
This will add the file to a native library, which starts the download of that file. You can watch the properties of the `IDownloadFile` instance and execute some code if e.g. the status changes to `COMPLETED`, you can also watch the `IDownloadManager.Queue` and execute some code if the list of files, that will be downloaded or are currently downloading changes.
@@ -60,28 +60,28 @@ When you choose not to provide your own path before starting the download, the d
6060
#### Recommended Option - Custom Location
6161

6262
Usually, you would expect to set the path to the `IDownloadFile` instance, you get when calling `downloadManager.CreateDownloadFile(url)`. But, as this download manager even continues downloading when the app crashed, you have to be able to reconstruct the path in every stage of the app. The correct way is to register a method as early as possible, that, in every circumstance, can reconstruct the path that the file should be saved. This method could look like following:
63-
```
64-
CrossDownloadManager.Current.PathNameForDownloadedFile = new System.Func<IDownloadFile, string> (file => {
63+
```csharp
64+
CrossDownloadManager.Current.PathNameForDownloadedFile = new System.Func<IDownloadFile, string> (file => {
6565
#if __IOS__
66-
string fileName = (new NSUrl(file.Url, false)).LastPathComponent;
67-
return Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), fileName);
66+
string fileName = (new NSUrl(file.Url, false)).LastPathComponent;
67+
return Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), fileName);
6868
#elif __ANDROID__
69-
string fileName = Android.Net.Uri.Parse(file.Url).Path.Split('/').Last();
70-
return Path.Combine (ApplicationContext.GetExternalFilesDir (Android.OS.Environment.DirectoryDownloads).AbsolutePath, fileName);
69+
string fileName = Android.Net.Uri.Parse(file.Url).Path.Split('/').Last();
70+
return Path.Combine (ApplicationContext.GetExternalFilesDir (Android.OS.Environment.DirectoryDownloads).AbsolutePath, fileName);
7171
#else
72-
string fileName = '';
73-
return Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), fileName);
72+
string fileName = '';
73+
return Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), fileName);
7474
#endif
75-
});
75+
});
7676
```
7777

7878
**Warning:** Please check if the files exist. The CrossDownloadManager will overwrite the file if it already exists.
7979

8080
##### Additional for Andriod
8181

8282
On Android, the destination location must be a located outside of your Apps internal directory (see [#10](https://github.com/SimonSimCity/Xamarin-CrossDownloadManager/issues/10) for details). To allow your app to write to that location, you either have to add the permission `WRITE_EXTERNAL_STORAGE` to the mainfest.xml file to require it when installing the app
83-
```
84-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
83+
```xml
84+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
8585
```
8686

8787
or to request it at runtime (See [#20](https://github.com/SimonSimCity/Xamarin-CrossDownloadManager/issues/20)).
@@ -92,18 +92,20 @@ All finished downloads are registered in a native `Downloads` application. If yo
9292

9393
Just register the instance in `CrossDownloadManager.Current` in the library. Here's an example how to do it on MvvmCross:
9494

95-
Mvx.RegisterSingleton<IDownloadManager>(() => CrossDownloadManager.Current);
95+
```csharp
96+
Mvx.RegisterSingleton<IDownloadManager>(() => CrossDownloadManager.Current);
97+
```
9698

9799
### Can I have a look at a sample implementation?
98100

99101
I've created a quite basic implementation for UWP, iOS and Android which you can find [here](https://github.com/SimonSimCity/Xamarin-CrossDownloadManager/tree/develop/Sample). Feel free to fork this repository and play around with it. It's right within the `Sample` folder.
100102

101103
### Why do the files show up in the native Android Download Manager?
102104

103-
That is the default behavior when downloading files using the Android DownladManager API. If you don't want this to happen you can change the property IsVisibleInDownloadsUi of the DownloadManagerImplementation
105+
This is the default of the native download manager on Android. You can change this behavior by setting the property `IsVisibleInDownloadsUi` of the Android implementation of the download manager to `false`. Here's an example which you can copy into your Android application:
104106

105-
```
106-
(CrossDownloadManager.Current as DownloadManagerImplementation).IsVisibleInDownloadsUi = false;
107+
```csharp
108+
(CrossDownloadManager.Current as DownloadManagerImplementation).IsVisibleInDownloadsUi = false;
107109
```
108110

109111
### Contribute / Bugs / Features

0 commit comments

Comments
 (0)