NativeScript / nativescript-background-http

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

Disabling notifications on Android Oreo: IllegalArgumentException #177

Closed mariuspruski closed 5 years ago

mariuspruski commented 5 years ago

Issue Disabling the notifications via androidDisplayNotificationProgress: false produces the following Exception on Android Oreo devices:

JS: ERROR Error: Uncaught (in promise): Error: java.lang.IllegalArgumentException: Android Oreo requires a notification configuration for the service to run. https://developer.android.com/reference/android/content/Context.html#startForegroundService(android.content.Intent)
JS:     net.gotev.uploadservice.UploadRequest.startUpload(UploadRequest.java:72)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:996)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:983)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:967)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:959)
JS:     com.tns.gen.java.lang.Runnable.run(Runnable.java:15)
JS:     android.os.Handler.handleCallback(Handler.java:789)
JS:     android.os.Handler.dispatchMessage(Handler.java:98)
JS:     android.os.Looper.loop(Looper.java:164)
JS:     android.app.ActivityThread.main(ActivityThread.java:6944)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     com.android.interna...

Versions affected Starting from 3.2.1 up to including the current version (3.3.0).

mariuspruski commented 5 years ago

Note: I have tested the current master branch (which includes some fixes for Android Oreo) and this issue is still present.

zbranzov commented 5 years ago

Hi @mariuspruski , Since API26, Android requires developers to use notifications when running background tasks https://developer.android.com/about/versions/oreo/background , that's why you get ERROR Error: Uncaught (in promise): Error: java.lang.IllegalArgumentException: Android Oreo requires a notification configuration for the service to run. https://developer.android.com/reference/android/content/Context.html#startForegroundService(android.content.Intent) My suggestion is to add logic in your app and turn the notifications off for devices below api 26.

elena-p commented 5 years ago

Closing the issue due to inactivity