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

Fatal exception. Bad notification for startForeground. #59

Closed
dtuite opened this issue Feb 1, 2018 · 11 comments
Closed

Fatal exception. Bad notification for startForeground. #59

dtuite opened this issue Feb 1, 2018 · 11 comments

Comments

@dtuite
Copy link
Contributor

dtuite commented Feb 1, 2018

This exception occurs in SDK 27 (Android 8.1) but not in lower SDK versions.

Fatal Exception: android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x42 color=0x00000000 groupKey=com.clamber vis=PRIVATE)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1768)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6494)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Turning off notifications prevents the exception from occurring.

    const options = {
      // ...
      notification: {
        // Required to prevent 
        enabled: false,
      },
    };

The issue appears to be fairly common and widely document for other libraries. I believe this is the same issue on SO.

I don't have a reproduction available but I believe there is one in an issue on this other upload library

@TSMMark
Copy link
Contributor

TSMMark commented Feb 1, 2018

Thanks for the report @dtuite. Do you think you could submit a PR?

@dtuite
Copy link
Contributor Author

dtuite commented Feb 1, 2018

I just had a look at the Java files you have in here and honestly I doubt I can. I don't know any Java or anything about native android libraries really so it would probably take me weeks to learn and follow through all the docs. If I could see a simple way to modify UploaderModule.java to look more like that in the SO answer I linked to I'd do it but that doesn't seem to be the case.

@TSMMark
Copy link
Contributor

TSMMark commented Feb 2, 2018

@dtuite I talked with the team and we don't have the bandwidth to prioritize diagnosing and fixing this exception at the moment; however, if notification: { enabled: false } really does fix the issue, we would be happy to accept a PR that simply adds this clause to the documentation!

@dtuite
Copy link
Contributor Author

dtuite commented Feb 2, 2018

Ready for review.

@watadarkstar
Copy link
Contributor

@TSMMark @dtuite Would be nice if this library auto checked the Platform.Version and turned of notifications for this issue automatically for APK 27 and greater.

See: https://facebook.github.io/react-native/docs/platform-specific-code.html

@TSMMark
Copy link
Contributor

TSMMark commented Apr 10, 2018

@watadarkstar Good idea! PRs welcome :)

@watadarkstar
Copy link
Contributor

If I have some time I'll tackle this @TSMMark but no promises 🙏

@StevePotter
Copy link
Contributor

@watadarkstar @TSMMark how about we turn off notifications by default? We'd have to do a major version bump and release notes but it's a very easy fix.

@watadarkstar
Copy link
Contributor

@StevePotter I'd prefer that they were on by default and disabled on APK 27 and greater automatically. Seems like a cleaner experience and probably still very little work (a one or two liner).

@peterent
Copy link

Using APK 28. After searching and searching I finally found this thread. I turned notification off. Now the app doesn't crash. Instead, it throws this error:
"Android Oreo requires a notification configuration for the service to run. https://developer.android.com/reference/android/content/Context.html#startForegroundService(android.content.Intent)"

@dwilt
Copy link

dwilt commented Aug 27, 2019

Running into the same issue as @peterent. Had to keep enabled: true but also add autoClear: true so they immediately hide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants