question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does not work with Android 8.0.0?

See original GitHub issue

Hello,

I have a Sony Xperia X with Android 8.0.0 and I just get an error with I call the function uploadFile(). The code works fine on Samsung S6 Android 7.0 and on iOS.

Note that no request ever arrives to the server so it’s not a network error. It does not work on http nor https server.

Here is the portion of code if it helps

import * as bghttpModule from 'nativescript-background-http';


    constructor(
        ...
    ) {
        ...
        this.session = bghttpModule.session('image-upload-bg-http');
    }


    private sendImages(fileUri): Q.Promise<any> {
        const defer = Q.defer();

        const imageName = this.extractImageName(fileUri);

        const request = {
            url: ... [[ some rest api url ]],
            method: 'PATCH',
            headers: {
                'Content-Type': 'application/octet-stream',
                'File-Name': imageName,
                'Content-Disposition': `attachment; filename=${imageName}`,
                Authorization: ... [[anonymized]],
            },
            description: "{ 'uploading': " + imageName + ' }',
        };

        const task = this.session.uploadFile(fileUri, request);

        task.on('progress', logEvent);
        task.on('error', err => {
            defer.reject(err);
        });
        task.on('complete', () => {
            defer.resolve();
        });

        function logEvent(e) {
            console.log('currentBytes: ' + e.currentBytes);
            console.log('totalBytes: ' + e.totalBytes);
            console.log('eventName: ' + e.eventName);
        }

        return defer.promise;
    }

Here is the error log I have.

JS: === dump(): dumping members ===
JS: {
JS:     "eventName": "error",
JS:     "object": {
JS:         "_observers": {
JS:             "progress": [
JS:                 {
JS:                     "callback": "callback()function logEvent(e) {\n            console.log('currentBytes: ' + e.currentBytes);\n            console.log('totalBytes: ' + e.totalBytes);\n            console.log('eventName: ' + e.eventName);\n        }"
JS:                 }
JS:             ],
JS:             "error": [
JS:                 {
JS:                     "callback": "callback()function (err) {\n            defer.reject(err);\n        }"
JS:                 }
JS:             ],
JS:             "complete": [
JS:                 {
JS:                     "callback": "callback()function () {\n            defer.resolve();\n        }"
JS:                 }
JS:             ]
JS:         },
JS:         "_session": {
JS:             "_id": "image-upload-bg-http"
JS:         },
JS:         "_id": "image-upload-bg-http{1}",
JS:         "_description": "{ 'uploading': random-avatar-2.png }",
JS:         "_upload": 0,
JS:         "_totalUpload": 1,
JS:         "_status": "error"
JS:     },
JS:     "error": null
JS: }
JS: === dump(): dumping function and properties names ===
JS: === dump(): finished ===

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
fthuincommented, Apr 1, 2018

It looks like for Android 8.0 we have to create a NotificationChannel.

The code to do it in Java is located at https://github.com/gotev/android-upload-service/blob/master/uploadservice/src/main/java/net/gotev/uploadservice/UploadTask.java in the function init()

    protected void init(UploadService service, Intent intent) throws IOException {
        this.notificationManager = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE);
        this.params = intent.getParcelableExtra(UploadService.PARAM_TASK_PARAMETERS);
        this.service = service;
        this.mainThreadHandler = new Handler(service.getMainLooper());

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && params.notificationConfig != null) {
            String notificationChannelId = params.notificationConfig.getNotificationChannelId();

            if (notificationChannelId == null) {
                params.notificationConfig.setNotificationChannelId(UploadService.NAMESPACE);
                notificationChannelId = UploadService.NAMESPACE;
            }

            if (notificationManager.getNotificationChannel(notificationChannelId) == null) {
                NotificationChannel channel = new NotificationChannel(notificationChannelId, "Upload Service channel", NotificationManager.IMPORTANCE_LOW);
                notificationManager.createNotificationChannel(channel);
            }
        }

    }

But it looks like this part is never called.

A quick fix is to modify in background-http-android.ts

        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);
        }

There is a missing check for the API version but I don’t know if a real fix in a pull request would not be better.

2reactions
fthuincommented, Apr 17, 2018

I confirm that everything is working well on my side. Do not hesitate to force the last version by updating your package.json, removing node_modules and platforms and do a clean run.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android 8.0 Oreo problems list, Dec 2022 - Product Reviews Net
Android 8.0 Oreo problems include: – Installation problem with a 'Couldn't Update' message popping up on screen. – Battery life drain complaints on...
Read more >
Android 8.0 Compatibility Definition
This document enumerates the requirements that must be met in order for devices to be compatible with Android 8.0. The use of “MUST”,...
Read more >
Is Android 8.0 still supported? - Quora
No, it is unsupported as far as apps are concerned most still run, but Google says it is unsupported, and it no longer...
Read more >
10 Common Android 8.1 Oreo Problems & How to Fix Them
If your Nexus or Pixel is randomly rebooting itself, here are a few remedies to try before contacting Google for a potential replacement...
Read more >
Android 8.0 Known Issue: WebView issue on work profile
Android devices with work profiles running Android Oreo (Android 8.0) may be affected by the following known issue. Fully managed devices remain unaffected....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found