plugins
plugins copied to clipboard
[background-http] App crashes due to IllegalArgumentException
Latest @nativescript/background-http
crashes some Android devices with You have to set namespace to your app package name (context.packageName) in your Application subclass
:
Caused by: java.lang.IllegalArgumentException:
at net.gotev.uploadservice.UploadServiceConfig.getNamespace (UploadServiceConfig.kt:74)
at net.gotev.uploadservice.UploadServiceConfig.getBroadcastNotificationAction (UploadServiceConfig.kt:234)
at net.gotev.uploadservice.UploadServiceConfig.getBroadcastNotificationActionIntentFilter (UploadServiceConfig.kt:248)
at net.gotev.uploadservice.observer.request.NotificationActionsObserver.register (NotificationActionsObserver.kt:31)
at net.gotev.uploadservice.UploadService.onCreate (UploadService.kt:194)
at android.app.ActivityThread.handleCreateService (ActivityThread.java:4641)
Full trace from Google Play Console:
java.lang.RuntimeException:
at android.app.ActivityThread.handleCreateService (ActivityThread.java:4655)
at android.app.ActivityThread.access$2800 (ActivityThread.java:251)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2319)
at android.os.Handler.dispatchMessage (Handler.java:110)
at android.os.Looper.loop (Looper.java:219)
at android.app.ActivityThread.main (ActivityThread.java:8393)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1055)
Caused by: java.lang.IllegalArgumentException:
at net.gotev.uploadservice.UploadServiceConfig.getNamespace (UploadServiceConfig.kt:74)
at net.gotev.uploadservice.UploadServiceConfig.getBroadcastNotificationAction (UploadServiceConfig.kt:234)
at net.gotev.uploadservice.UploadServiceConfig.getBroadcastNotificationActionIntentFilter (UploadServiceConfig.kt:248)
at net.gotev.uploadservice.observer.request.NotificationActionsObserver.register (NotificationActionsObserver.kt:31)
at net.gotev.uploadservice.UploadService.onCreate (UploadService.kt:194)
at android.app.ActivityThread.handleCreateService (ActivityThread.java:4641)
Calling init()
from the main.ts
does not help this particular problem, because error occurs while having this in my main.ts
:
import { init } from "@nativescript/background-http";
init();
According to https://github.com/gotev/android-upload-service/issues/510 createNotificationChannel()
needs to be called explicitly.
Might be related to #274
@grigala : Have you found a solution for this? I am also stuck with the same problem
Hi @pap5508, nothing that's 100% tested so far, but you can give it a try and do this before you call/construct bghttp session:
if (android.os.Build.VERSION.SDK_INT >= 26) {
const channel = new android.app.NotificationChannel(
"NotificationChannel",
"My App",
android.app.NotificationManager.IMPORTANCE_HIGH // adjust to your requirement
);
const manager = Utils.android
.getApplicationContext()
.getSystemService(android.content.Context.NOTIFICATION_SERVICE) as android.app.NotificationManager;
manager.createNotificationChannel(channel);
}
if (android.os.Build.VERSION.SDK_INT >= 26) { ...
I can't get it working with this. Get the same error.
The init()
function is new, .. after adding it I have this issue resolved for now.
I face the same issue. However, the init() calling before uploading multipart still gives me the same error... Where are you calling the init? main.ts still?
@Maxeeezy : Yes, I have added in main.ts and working fine.
I run into this issue as well on Android. Not every upload (we use init()
) but some fail.
Caused by java.lang.IllegalArgumentException: You have to set namespace to your app package name (context.packageName) in your Application subclass
at net.gotev.uploadservice.UploadServiceConfig.getNamespace(UploadServiceConfig.kt:74)
at net.gotev.uploadservice.UploadServiceConfig.getBroadcastNotificationAction(UploadServiceConfig.kt:234)
at net.gotev.uploadservice.UploadServiceConfig.getBroadcastNotificationActionIntentFilter(UploadServiceConfig.kt:248)
(extra info but theory: I think it's related to coming back from a Camera activity and somehow that namespace is not ready. I called init() in appResume (should be idempotent if already initialized) but that doesn't seem to fix it completely)