diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 8d2a616..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,109 +0,0 @@
-branches:
- only:
- - master
-matrix:
- include:
- - stage: "Lint"
- language: node_js
- os: linux
- node_js: "10"
- script:
- - cd src && npm run ci.tslint
- - cd ../demo && npm run ci.tslint
- - cd ../demo-angular && npm run ci.tslint
- - stage: "WebPack"
- os: osx
- env:
- - WebPack="iOS"
- - Type="TypeScript"
- osx_image: xcode10.2
- language: node_js
- node_js: "10"
- jdk: oraclejdk8
- script:
- - cd demo && npm run build.plugin && npm i
- - tns build ios --bundle --env.uglify
- - os: osx
- env:
- - WebPack="iOS"
- - Type="Angular"
- osx_image: xcode10.2
- language: node_js
- node_js: "10"
- jdk: oraclejdk8
- script:
- - cd src && npm run build
- - cd ../publish && sh pack.sh
- - cd ../demo-angular
- - tns plugin add ../publish/package/*.tgz
- - tns build ios --bundle --env.uglify --env.aot
- - os: osx
- env:
- - WebPack="iOS"
- - Type="Vue"
- osx_image: xcode10.2
- language: node_js
- node_js: "10"
- jdk: oraclejdk8
- script:
- - cd src && npm run build
- - cd ../publish && sh pack.sh
- - cd ../demo-vue
- - tns plugin add ../publish/package/*.tgz
- - tns build ios --bundle --env.uglify
- - language: android
- os: linux
- dist: trusty
- env:
- - WebPack="Android"
- - Type="TypeScript"
- jdk: oraclejdk8
- before_install: nvm install 10
- script:
- - cd demo && npm run build.plugin
- - tns build android --bundle --env.uglify --env.snapshot
- - language: android
- os: linux
- dist: trusty
- env:
- - WebPack="Android"
- - Type="Angular"
- jdk: oraclejdk8
- before_install: nvm install 10
- script:
- - cd src && npm run build
- - cd ../publish && sh pack.sh
- - cd ../demo-angular
- - tns plugin add ../publish/package/*.tgz
- - tns build android --bundle --env.uglify --env.aot
- - language: android
- os: linux
- dist: trusty
- env:
- - WebPack="Android"
- - Type="Vue"
- jdk: oraclejdk8
- before_install: nvm install 10
- script:
- - cd src && npm run build
- - cd ../publish && sh pack.sh
- - cd ../demo-vue
- - tns plugin add ../publish/package/*.tgz
- - tns build android --bundle --env.uglify --env.aot
-
-android:
- components:
- - tools
- - platform-tools
- - build-tools-28.0.3
- - android-28
- - extra-android-m2repository
-
-before_install:
- - sudo pip install --upgrade pip
- - sudo pip install six
-
-install:
- - echo no | npm install -g nativescript
- - tns usage-reporting disable
- - tns error-reporting disable
diff --git a/DevelopmentWorkflow.md b/DevelopmentWorkflow.md
index 245f06c..b17c764 100644
--- a/DevelopmentWorkflow.md
+++ b/DevelopmentWorkflow.md
@@ -5,6 +5,7 @@
- [Prerequisites](#prerequisites)
- [Develop locally](#develop-locally)
- [Testing the plugin](#testing-the-plugin)
+- [Native android changes](#native-android-changes)
@@ -34,4 +35,15 @@ npm run demo.android
The demo application is configured to run on a simulator/emulator on the local machine. If you want to test on a real device, you should change the URL in the `demo/app/home-view-model.ts` to point to the machine that is running the demo server. Be careful if using an online test service, e.g. [http://httpbin.org/post](http://httpbin.org/post). Some services are configured to return the uploaded file contents in the server response, which might crash the demo app if the uploaded file is large.
+## Native android changes
+
+For android, the plugin uses [a fork](https://github.com/NativeScript/android-upload-service) of the [gotev/android-upload-service](https://github.com/gotev/android-upload-service) library for Android.
+Avoid fixes and new features in the fork. Use the original repository and then update the fork with the changes.
+The native library is used in the plugin as an aar file added in the plugin's platforms/android directory.
+Here's how to reflect any changes in the native library in this plugin. First make sure the changes are included in the fork. Then clone the fork and run the following command in its root directory:
+```
+./gradlew clean assembleRelease
+```
+This will produce a new aar file here: android-upload-service/uploadservice/build/outputs/aar/uploadservice-release.aar. Use it to replace the previous aar in the plugin: nativescript-background-http/src/platforms/android/uploadservice-release.aar
+
For details on plugins development workflow, read [NativeScript plugins documentation](https://docs.nativescript.org/plugins/building-plugins#step-2-set-up-a-development-workflow) covering that topic.
diff --git a/README.md b/README.md
index 5d71309..01c16c4 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,17 @@
+## NativeScript 7
+
+* Use `@nativescript/background-http`: `~5.0.0`
+* [Source managed here](https://github.com/NativeScript/plugins)
+
+## If using 6 and below, see the following:
+
# Background Upload NativeScript plugin [](https://travis-ci.org/NativeScript/nativescript-background-http)
A cross platform plugin for [the NativeScript framework](http://www.nativescript.org), that provides background upload for iOS and Android.
[There is a stock NativeScript `http` module that can handle GET/POST requests that work with strings and JSONs](http://docs.nativescript.org/ApiReference/http/HOW-TO). It however comes short in features when it comes to really large files.
-The plugin uses [NSURLSession with background session configuration for iOS](https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSessionConfiguration_class/index.html#//apple_ref/occ/clm/NSURLSessionConfiguration/backgroundSessionConfigurationWithIdentifier:); and the [alexbbb/android-upload-service](https://github.com/alexbbb/android-upload-service) library for Android.
+The plugin uses [NSURLSession with background session configuration for iOS](https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSessionConfiguration_class/index.html#//apple_ref/occ/clm/NSURLSessionConfiguration/backgroundSessionConfigurationWithIdentifier:); and [a fork](https://github.com/NativeScript/android-upload-service) of the [gotev/android-upload-service](https://github.com/gotev/android-upload-service) library for Android.
## Installation
@@ -76,6 +83,9 @@ androidDisplayNotificationProgress | `boolean` | (Android only) Used to set if p
androidNotificationTitle | `string` | (Android only) Used to set the title shown in the Android notifications center.
androidAutoDeleteAfterUpload | `boolean` | (Android only) Used to set if files should be deleted automatically after upload.
androidMaxRetries | `number` | (Android only) Used to set the maximum retry count. The default retry count is 0. https://github.com/gotev/android-upload-service/wiki/Recipes#backoff
+androidAutoClearNotification | `boolean` | (Android only) Used to set if notifications should be cleared automatically upon upload completion. Default is false. Please note that setting this to true will also disable the ringtones.
+androidRingToneEnabled | `boolean` | (Android only) Used to set if a ringtone should be played upon upload completion. Default is true. Please note that this flag has no effect when `androidAutoClearNotification` is set to true.
+androidNotificationChannelID | `string` | (Android only) Used to set the channel ID for the notifications.
The task object has the following properties and methods, that can be used to get information about the upload:
diff --git a/demo-angular/app/App_Resources/Android/src/main/AndroidManifest.xml b/demo-angular/app/App_Resources/Android/src/main/AndroidManifest.xml
index adb8ac1..b288a62 100644
--- a/demo-angular/app/App_Resources/Android/src/main/AndroidManifest.xml
+++ b/demo-angular/app/App_Resources/Android/src/main/AndroidManifest.xml
@@ -11,7 +11,7 @@
android:xlargeScreens="true"/>
diff --git a/demo-angular/app/home/home.component.ts b/demo-angular/app/home/home.component.ts
index 941113f..940ab46 100644
--- a/demo-angular/app/home/home.component.ts
+++ b/demo-angular/app/home/home.component.ts
@@ -68,6 +68,8 @@ export class HomeComponent {
if (isMulti) {
const params = [
{ name: "test", value: "value" },
+ { name: "testInt", value: 10 },
+ { name: "bool", value: true },
{ name: "fileToUpload", filename: this.file, mimeType: 'image/jpeg' }
];
task = this.session.multipartUpload(params, request);
diff --git a/demo-angular/app/package.json b/demo-angular/app/package.json
index ee8642e..8d72b14 100644
--- a/demo-angular/app/package.json
+++ b/demo-angular/app/package.json
@@ -1,7 +1,10 @@
{
"android": {
"v8Flags": "--expose_gc",
- "requireModules": ["nativescript-background-http"]
+ "requireModules": [
+ "nativescript-background-http"
+ ],
+ "markingMode": "none"
},
"main": "main.js"
-}
\ No newline at end of file
+}
diff --git a/demo-angular/package.json b/demo-angular/package.json
index 05da1a2..861d88d 100644
--- a/demo-angular/package.json
+++ b/demo-angular/package.json
@@ -6,10 +6,10 @@
"nativescript": {
"id": "org.nativescript.demoangular",
"tns-android": {
- "version": "6.0.0"
+ "version": "6.2.0"
},
"tns-ios": {
- "version": "6.0.1"
+ "version": "6.2.0"
}
},
"scripts": {
@@ -17,27 +17,26 @@
"ci.tslint": "npm i && tslint --config '../tslint.json' 'app/**/*.ts' --exclude '**/node_modules/**'"
},
"dependencies": {
- "@angular/animations": "~8.0.0",
- "@angular/common": "~8.0.0",
- "@angular/compiler": "~8.0.0",
- "@angular/core": "~8.0.0",
- "@angular/forms": "~8.0.0",
- "@angular/http": "8.0.0-beta.10",
- "@angular/platform-browser": "~8.0.0",
- "@angular/platform-browser-dynamic": "~8.0.0",
- "@angular/router": "~8.0.0",
- "nativescript-angular": "~8.0.0",
+ "@angular/animations": "~8.2.0",
+ "@angular/common": "~8.2.0",
+ "@angular/compiler": "~8.2.0",
+ "@angular/core": "~8.2.0",
+ "@angular/forms": "~8.2.0",
+ "@angular/platform-browser": "~8.2.0",
+ "@angular/platform-browser-dynamic": "~8.2.0",
+ "@angular/router": "~8.2.0",
+ "nativescript-angular": "~8.20.0",
"nativescript-background-http": "../src",
"nativescript-theme-core": "~1.0.4",
"reflect-metadata": "~0.1.10",
- "rxjs": "^6.3.3",
+ "rxjs": "^6.4.0",
"tns-core-modules": "^6.0.0",
"zone.js": "^0.9.1"
},
"devDependencies": {
- "nativescript-dev-webpack": "~1.0.1",
+ "nativescript-dev-webpack": "^1.3.0",
"tslint": "~5.11.0",
"tns-platform-declarations": "^6.0.0",
- "typescript": "~3.4.5"
+ "typescript": "~3.5.3"
}
-}
\ No newline at end of file
+}
diff --git a/demo-vue/app/App_Resources/Android/AndroidManifest.xml b/demo-vue/app/App_Resources/Android/AndroidManifest.xml
index d05f4de..b70b530 100644
--- a/demo-vue/app/App_Resources/Android/AndroidManifest.xml
+++ b/demo-vue/app/App_Resources/Android/AndroidManifest.xml
@@ -11,7 +11,7 @@
android:xlargeScreens="true"/>
@@ -19,6 +19,7 @@
diff --git a/demo/app/home/home-view-model.ts b/demo/app/home/home-view-model.ts
index 8dbef2e..07fc797 100644
--- a/demo/app/home/home-view-model.ts
+++ b/demo/app/home/home-view-model.ts
@@ -68,6 +68,8 @@ export class HomeViewModel extends Observable {
if (isMulti) {
const params = [
{ name: "test", value: "value" },
+ { name: "testInt", value: 10 },
+ { name: "bool", value: true },
{ name: "fileToUpload", filename: this.file, mimeType: 'image/jpeg' }
];
task = this.session.multipartUpload(params, request);
diff --git a/demo/app/package.json b/demo/app/package.json
index a7511e3..1e162ea 100644
--- a/demo/app/package.json
+++ b/demo/app/package.json
@@ -1,7 +1,10 @@
{
"android": {
"v8Flags": "--expose_gc",
- "requireModules": ["nativescript-background-http"]
+ "requireModules": [
+ "nativescript-background-http"
+ ],
+ "markingMode": "none"
},
"main": "app.js"
-}
\ No newline at end of file
+}
diff --git a/demo/package.json b/demo/package.json
index 5dbbdbd..bffcbbf 100644
--- a/demo/package.json
+++ b/demo/package.json
@@ -6,10 +6,10 @@
"nativescript": {
"id": "org.nativescript.demo",
"tns-android": {
- "version": "6.0.0"
+ "version": "6.2.0"
},
"tns-ios": {
- "version": "6.0.1"
+ "version": "6.2.0"
}
},
"scripts": {
@@ -22,9 +22,9 @@
"tns-core-modules": "^6.0.0"
},
"devDependencies": {
- "nativescript-dev-webpack": "~1.0.1",
+ "nativescript-dev-webpack": "^1.3.0",
"tslint": "~5.11.0",
"tns-platform-declarations": "^6.0.0",
- "typescript": "~3.4.5"
+ "typescript": "~3.5.3"
}
}
diff --git a/src/.npmignore b/src/.npmignore
index 1a3062f..6ab38bf 100644
--- a/src/.npmignore
+++ b/src/.npmignore
@@ -7,5 +7,4 @@ tsconfig.json
*.tgz
/package
/platforms/android/**/*
-!platforms/android/include.gradle
-!platforms/android/nativescript_background_http.aar
\ No newline at end of file
+!platforms/android/uploadservice-release.aar
\ No newline at end of file
diff --git a/src/background-http.android.ts b/src/background-http.android.ts
index 4729ac6..7ead237 100644
--- a/src/background-http.android.ts
+++ b/src/background-http.android.ts
@@ -278,17 +278,18 @@ function getMultipartRequest(taskId: string, options: common.Request, params: an
if (typeof curParam.name === 'undefined') {
throw new Error("You must have a `name` value");
}
- if (curParam.filename) {
- let fileName = curParam.filename;
- if (fileName.startsWith("~/")) {
- fileName = fileName.replace("~/", fileSystemModule.knownFolders.currentApp().path + "/");
- }
- const destFileName = curParam.destFilename || fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length);
- request.addFileToUpload(fileName, curParam.name, destFileName, curParam.mimeType);
+
+ if (typeof curParam.filename === 'undefined') {
+ request.addParameter(curParam.name.toString(), curParam.value.toString());
+ continue;
}
- else {
- request.addParameter(params[i].name, params[i].value);
+
+ let fileName = curParam.filename;
+ if (fileName.startsWith("~/")) {
+ fileName = fileName.replace("~/", fileSystemModule.knownFolders.currentApp().path + "/");
}
+ const destFileName = curParam.destFilename || fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length);
+ request.addFileToUpload(fileName, curParam.name, destFileName, curParam.mimeType);
}
const utf8 = options.utf8;
@@ -307,7 +308,23 @@ function setRequestOptions(request: any, options: common.Request) {
if (displayNotificationProgress) {
const uploadNotificationConfig = new net.gotev.uploadservice.UploadNotificationConfig();
const notificationTitle = typeof options.androidNotificationTitle === "string" ? options.androidNotificationTitle : 'File Upload';
+
uploadNotificationConfig.setTitleForAllStatuses(notificationTitle);
+
+ if (typeof options.androidRingToneEnabled === "boolean") {
+ uploadNotificationConfig.setRingToneEnabled(new java.lang.Boolean(options.androidRingToneEnabled));
+ }
+
+ if (typeof options.androidAutoClearNotification === "boolean") {
+ uploadNotificationConfig.getCompleted().autoClear = options.androidAutoClearNotification;
+ uploadNotificationConfig.getCancelled().autoClear = options.androidAutoClearNotification;
+ uploadNotificationConfig.getError().autoClear = options.androidAutoClearNotification;
+ }
+
+ if (typeof options.androidNotificationChannelID === "string" && options.androidNotificationChannelID) {
+ uploadNotificationConfig.setNotificationChannelId(options.androidNotificationChannelID);
+ }
+
request.setNotificationConfig(uploadNotificationConfig);
}
const autoDeleteAfterUpload = typeof options.androidAutoDeleteAfterUpload === "boolean" ? options.androidAutoDeleteAfterUpload : false;
diff --git a/src/index.d.ts b/src/index.d.ts
index 2240ab8..9e66108 100644
--- a/src/index.d.ts
+++ b/src/index.d.ts
@@ -85,12 +85,12 @@ export interface Task {
* Cancel the Upload Task.
*/
cancel(): void;
- /**
- * Subscribe for a general event.
- * @param event The name of the event to subscribe for.
- * @param handler The handler called when the event occure.
- * @event
- */
+ /**
+ * Subscribe for a general event.
+ * @param event The name of the event to subscribe for.
+ * @param handler The handler called when the event occure.
+ * @event
+ */
on(event: string, handler: (e: observable.EventData) => void): void;
/**
@@ -194,4 +194,19 @@ export interface Request {
* https://github.com/gotev/android-upload-service/wiki/Recipes#backoff
*/
androidMaxRetries?: number;
+
+ /*
+ * Use this to set if notifications should be cleared automatically upon upload completion
+ */
+ androidAutoClearNotification?: boolean;
+
+ /*
+ * Use this to set if a ringtone should be played upon upload completion
+ */
+ androidRingToneEnabled?: boolean;
+
+ /*
+ * Use this to set the channel ID for the notifications
+ */
+ androidNotificationChannelID?: string;
}
diff --git a/src/package.json b/src/package.json
index 0234517..6867f41 100644
--- a/src/package.json
+++ b/src/package.json
@@ -1,6 +1,6 @@
{
"name": "nativescript-background-http",
- "version": "4.0.0",
+ "version": "4.2.1",
"main": "background-http",
"typings": "index.d.ts",
"nativescript": {
@@ -17,12 +17,9 @@
"scripts": {
"tsc": "tsc -skipLibCheck",
"build": "npm i && tsc",
- "postclone": "npm i && node scripts/postclone.js && cd ../demo && npm i && cd ../src && npm run plugin.link",
"test.android": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build android && tns test android --justlaunch",
"test.ios": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build ios && tns test ios --justlaunch",
"tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\"",
- "plugin.link": "npm link && cd ../demo && npm link nativescript-background-http && cd ../src",
- "plugin.tscwatch": "npm run tsc -- -w",
"demo.ios": "npm i && npm run tsc && cd ../demo && tns run ios",
"demo-angular.ios": "npm i && npm run tsc && cd ../demo-angular && tns run ios",
"demo-vue.ios": "npm i && npm run tsc && cd ../demo-vue && tns run ios",
@@ -34,8 +31,7 @@
"server": "cd ../demo-server && npm run start",
"plugin.prepare": "npm run tsc && cd ../demo && tns plugin remove nativescript-background-http && tns plugin add ../src",
"clean": "cd ../demo && rimraf hooks node_modules platforms && cd ../src && rimraf node_modules && npm run plugin.link",
- "ci.tslint": "npm i && tslint '**/*.ts' --config '../tslint.json' --exclude '**/node_modules/**'",
- "prepare": "node scripts/prepare.js"
+ "ci.tslint": "npm i && tslint '**/*.ts' --config '../tslint.json' --exclude '**/node_modules/**'"
},
"keywords": [
"background",
@@ -55,7 +51,7 @@
"devDependencies": {
"tns-core-modules": "^6.0.0",
"tns-platform-declarations": "^6.0.0",
- "typescript": "~3.1.6",
+ "typescript": "~3.5.3",
"rimraf": "~2.6.2",
"semver": "~5.6.0",
"tslint": "~5.11.0"
diff --git a/src/platforms/android/AndroidManifest.xml b/src/platforms/android/AndroidManifest.xml
deleted file mode 100644
index e927afa..0000000
--- a/src/platforms/android/AndroidManifest.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/platforms/android/include.gradle b/src/platforms/android/include.gradle
deleted file mode 100644
index 82bc6b2..0000000
--- a/src/platforms/android/include.gradle
+++ /dev/null
@@ -1,8 +0,0 @@
-//default elements
-android {
-}
-
-//optional elements
-dependencies {
- implementation 'net.gotev:uploadservice:3.5.2'
-}
\ No newline at end of file
diff --git a/src/platforms/android/uploadservice-release.aar b/src/platforms/android/uploadservice-release.aar
new file mode 100644
index 0000000..1ffef5a
Binary files /dev/null and b/src/platforms/android/uploadservice-release.aar differ
diff --git a/src/scripts/prepare.js b/src/scripts/prepare.js
deleted file mode 100644
index 79c030c..0000000
--- a/src/scripts/prepare.js
+++ /dev/null
@@ -1,21 +0,0 @@
-const { exec } = require('child_process');
-const semver = require('semver');
-
-exec('tns --version', (err, stdout, stderr) => {
- if (err) {
- // node couldn't execute the command
- console.log(`tns --version err: ${err}`);
- return;
- }
-
- const regex = /^(?:\d+\.){2}\d+.*?$/m;
- const matches = stdout.match(regex);
- console.log("Extracted tns version: " + matches[0]);
- const tnsVersion = semver.major(semver.coerce(matches[0]));
-
- // execute 'tns plugin build' for {N} version > 4. This command builds .aar in platforms/android folder.
- if (tnsVersion >= 4) {
- console.log(`executing 'tns plugin build'`);
- exec('tns plugin build');
- }
-});
\ No newline at end of file