NativeScript / nativescript-background-http

Background Upload plugin for the NativeScript framework
Apache License 2.0
101 stars 50 forks source link

Not working on Android 8.1.0 Pixel 2 XL with plugin version 3.2.3 #136

Closed FranciZ closed 6 years ago

FranciZ commented 6 years ago

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

When attempting upload I get the following error.

{"eventName":"error","object":{"_observers":{"progress":[{}],"error":[{}],"complete":[{}]},"_session":{"_id":"image-upload"},"_id":"image-upload{1}","_description":"{ 'uploading': IMG-20180421-WA0003.jpg }","_upload":0,"_totalUpload":1,"_status":"error"}}

This must be related to issue https://github.com/NativeScript/nativescript-background-http/issues/124, but the 3.2.3 release does not fix it for me.

I can get it working by applying the fix as described here, https://github.com/NativeScript/nativescript-background-http/issues/124#issuecomment-377788306.

I've tried removing the node_modules and reinstalling. I've tried removing tns platform remove android and reinstalling. Does not help.

Copy pasting the code from that comment into background-http.android.js works.

If I replace:

var displayNotificationProgress = typeof options.androidDisplayNotificationProgress === "boolean" ? options.androidDisplayNotificationProgress : true;
        if (displayNotificationProgress) {
            request.setNotificationConfig(new net.gotev.uploadservice.UploadNotificationConfig());
        }

with

const displayNotificationProgress = typeof options.androidDisplayNotificationProgress === "boolean" ? options.androidDisplayNotificationProgress : true;
        if (displayNotificationProgress) {
            const channel = new android.app.NotificationChannel(application.android.packageName, application.android.packageName,
                android.app.NotificationManager.IMPORTANCE_LOW);
            const notificationManager = context.getSystemService(android.content.Context.NOTIFICATION_SERVICE)
            notificationManager.createNotificationChannel(channel);

            const uploadNotificationConfig = new net.gotev.uploadservice.UploadNotificationConfig();
            uploadNotificationConfig.setNotificationChannelId(application.android.packageName)
            request.setNotificationConfig(uploadNotificationConfig);
        }

on lines 128 and 181 than it works.

lini commented 6 years ago

If you are still having trouble, try updating to the latest version of the plugin (3.2.5). It seems that you are still using an old version (with the old native dependency). If you can, try testing with one of the demo apps in this repository and see if the plugin works there. I tested them with a google device running android 8.1 and saw no issues.

FranciZ commented 6 years ago

I tried updating to the latest version 3.2.5 with no results. I've removed the node_modules and removed the android platform multiple times with no success. Is there some other place I could have files from older versions? Each time I replace the code as mentioned above and then it works.

Let me know what information I can provide to help further.

pauly815 commented 6 years ago

I'm observing the same issue as FranciZ on 3.2.5. I'm running TNS 3.4.2 on a Samsung S8 emulator with Android 8.0. Only thing that worked for me was the fix from issue #124.

pauly815 commented 6 years ago

Unfortunately that fix does not work when I build and deploy to a Samsung S6 on Android 7. I should also mention that I'm using nativescript angular.

Edit This makes sense since Android 7 (API 25) doesn't have the NotificationChannel class. I updated the #124 fix to check the SDK version to be greater than or equal to 26 to determine whether or not a channel needs to be created.

I'll submit a pull request when i get a chance but not sure if it'll get accepted if no one else is having this problem.

crowebird commented 6 years ago

I am having this issue as well.. nativescript-angular with background-http at 3.2.5 on sdk 26+ Going to give this fix a try.

Thanks @pauly815 / @FranciZ

Edit, for the record, this fixes things for me!

zbranzov commented 6 years ago

Hi, Can someone send an app so we can reproduce the issue? Currently, using the demo-angular sample from the repository we are unable to reproduce your case. We are testing on Nexus 5x and Pixel 2 (both Android 8.1) and latest plugin version.

pauly815 commented 6 years ago

I am no longer having the issue when upgrading to version 3.2.6.

radeva commented 6 years ago

Closing since the issue seems to be solved.