Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Customize UploadNotificationConfig #71

Closed
farzeni opened this issue Jun 15, 2017 · 14 comments
Closed

[Android] Customize UploadNotificationConfig #71

farzeni opened this issue Jun 15, 2017 · 14 comments

Comments

@farzeni
Copy link

farzeni commented Jun 15, 2017

Hello,

I'm writing an android application and I need to customize the behavior of upload notifications. My app does several small uploads in a short moment so i would like to disable the ringtone sound and to hide the notifications on upload success.

These options can be managed in UploadNotificationConfig object of android-upload-service library (here the docs), but are not customizable during creation of new background-http task.

here, the lines involved in task creation:

background-http.android.ts

130. request.setNotificationConfig(new (<any>net).gotev.uploadservice.UploadNotificationConfig());
...
186. request.setNotificationConfig(new (<any>net).gotev.uploadservice.UploadNotificationConfig());

Do you have any suggestion on how to modify nativescript-background-http to enable these options without breaking too much the compatibility with ios platform? or maybe another way to get the same result?

thanks

@farzeni farzeni changed the title [Android] Customize [Android] Customize UploadNotificationConfig Jun 15, 2017
@tsonevn
Copy link
Contributor

tsonevn commented Jun 23, 2017

Hi @farzeni,
I reviewed your case on my side, however, at this time there is no appropriate way to set up this options from code behind.

Regarding that, I log this issue as a new feature.

In the meantime, I could suggest setting those options inside the background-http.android.ts file as you have mentioned and to create your local tgz, which you could use in your project. You could follow the below-attached steps.

  1. git clone https://github.com/NativeScript/nativescript-background-http
  2. add in nativescript-background-http/background-http.android.ts file following settings inside the create method.
 static create(session: Session, file: string, options: common.Request): Task {
        var task = new Task();
        task._session = session;
        task._id = session.id + "{" + ++Task.taskCount + "}";

        var context = application.android.context;

        var request = new (<any>net).gotev.uploadservice.BinaryUploadRequest(context, task._id, options.url);

        request.setFileToUpload(file);

        request.setNotificationConfig(new (<any>net).gotev.uploadservice.UploadNotificationConfig());
        request.setFileToUpload(file);
        request.setRingToneEnabled(false);
        var headers = options.headers;
        if (headers) {
            for (var header in headers) {
                var value = headers[header];
                if (value !== null && value !== void 0) {
                    request.addHeader(header, value.toString());
                }
            }
        }
  1. npm install
    4, npm run tsc
  2. npm pack

the newly created tgz file could installed with tns plugin add <path to the file>

@dvdbrk
Copy link

dvdbrk commented Nov 8, 2017

Umm... I don't think this works, I get

JS: ERROR TypeError: request.setRingToneEnabled is not a function

@tomshabtay
Copy link

Hi, i also tried your suggested fix and got the same error.
TypeError: request.setRingToneEnabled is not a function

@tomshabtay
Copy link

I edited the the background-http.android.ts file once again and made the notification disappear completely.

Please consider adding this functionally to your plugin in your next update.

Thanks!

The change that i made was to comment this section:
var displayNotificationProgress = typeof options.androidDisplayNotificationProgress === "boolean" ? options.androidDisplayNotificationProgress : true; if (displayNotificationProgress) { request.setNotificationConfig(new (<any>net).gotev.uploadservice.UploadNotificationConfig()); }

@geoffbullen
Copy link

+1

@bniehuser
Copy link

bniehuser commented May 18, 2018

if you read the code you commented out, you will realize you can include the boolean flag 'androidDisplayNotificationProgress' in the options array passed to either 'uploadFile' or 'multipartUpload' (set to false to omit the notification).

thanks for pointing it out, looking at this thread is what finally made that option and its use click. :)

@geoffbullen
Copy link

@bniehuser - Thank you for pointing that out!

@andreasteffanoni
Copy link

+1

@geoffbullen
Copy link

@bniehuser note this doesn't appear to work for recent android versions. See #148

@AradhanaR
Copy link

AradhanaR commented Jun 26, 2018

Currently I am facing two issues with the plugin :

  • I am using nativescript-imagecropper with nativescript-background-http and it was working properly before updating the plugin nativescript-background-http to latest version and nativescript to 4.1.0 . But now app crashes with following error:

An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Error receiving broadcast Intent { act=com.proxible.innercircle.uploadservice.broadcast.status flg=0x10 pkg=com.proxible.innercircle (has extras) } in net.gotev.uploadservice.UploadServiceBroadcastReceiver_http_91_87_@61a749f
at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$-android_app_LoadedApk$ReceiverDispatcher$Args_53427(LoadedApk.java:1356)
at android.app.-$Lambda$FilBqgnXJrN9Mgyks1XHeAxzSTk.$m$0(Unknown Source:4)
at android.app.-$Lambda$FilBqgnXJrN9Mgyks1XHeAxzSTk.run(Unknown Source:0)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6798)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: com.tns.NativeScriptException:
Calling js method onCompleted failed

  • Another issue is that I need to disable upload notification on android but options.androidDisplayNotificationProgress is no longer available in recent version and above suggestions are not working.

Please suggest solutions asap.

@marcossaore
Copy link

@tomshabtay, Would you have this file updated.? I wanted to copy it. Do you know about any course that explains how to create plugins, sometimes I need change something on code but give up on the same time because of complexity of them.

@tomshabtay
Copy link

@manoldonev i used tsonevn explanation in this thread to edit the plugin.
I uploaded the edited plugin I used
nativescript-background-http-3.1.0.zip

@VladimirAmiorkov
Copy link
Contributor

This feature has been implemented is merged with #239

@zbranzov zbranzov moved this from Review / QA to Ready for Release in Plugins Team Sep 10, 2019
@zbranzov
Copy link
Contributor

Released in nativescript-background-http@4.1.0

Plugins Team automation moved this from Ready for Release to Done Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Plugins Team
  
Done
Development

No branches or pull requests