Skip to content

[Bug]: Receive notification when app is closed/background. #618

@davetebonfire0302

Description

@davetebonfire0302

What happened?

Followed instructions here and created a .java file in com.package.name now I have 2 files there MainActivity.java And NotificationServiceExtension.java

  <meta-data android:name="com.onesignal.NotificationServiceExtension"
            android:value="com.bonfire.cdis.NotificationServiceExtension" />

image

Steps to reproduce?

Use flutter 3.4.2
Follow instructions here https://documentation.onesignal.com/docs/service-extensions#android-notification-service-extension
Run the app

What did you expect to happen?

Expected to successfully run the app and receive notification when app is in foreground or background.

OneSignal Flutter SDK version

3.4.2

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

Launching lib\main.dart on sdk gphone x86 64 in debug mode...
Running Gradle task 'assembleDebug'...
D:\caps\cdis\android\app\src\main\java\com\bonfire\cdis\NotificationServiceExtension.java:24: error: cannot find symbol
            builder.setColor(new BigInteger("FF00FF00", 16).intValue());
                                 ^
  symbol:   class BigInteger
  location: class NotificationServiceExtension
D:\caps\cdis\android\app\src\main\java\com\bonfire\cdis\NotificationServiceExtension.java:26: error: cannot find symbol
            Spannable spannableTitle = new SpannableString(notification.getTitle());
            ^
  symbol:   class Spannable
  location: class NotificationServiceExtension
D:\caps\cdis\android\app\src\main\java\com\bonfire\cdis\NotificationServiceExtension.java:26: error: cannot find symbol
            Spannable spannableTitle = new SpannableString(notification.getTitle());
                                           ^
  symbol:   class SpannableString
  location: class NotificationServiceExtension
D:\caps\cdis\android\app\src\main\java\com\bonfire\cdis\NotificationServiceExtension.java:27: error: cannot find symbol
            spannableTitle.setSpan(new ForegroundColorSpan(Color.RED),0,notification.getTitle().length(),0);
                                       ^
  symbol:   class ForegroundColorSpan
  location: class NotificationServiceExtension
D:\caps\cdis\android\app\src\main\java\com\bonfire\cdis\NotificationServiceExtension.java:27: error: cannot find symbol
            spannableTitle.setSpan(new ForegroundColorSpan(Color.RED),0,notification.getTitle().length(),0);
                                                           ^
  symbol:   variable Color
  location: class NotificationServiceExtension
D:\caps\cdis\android\app\src\main\java\com\bonfire\cdis\NotificationServiceExtension.java:30: error: cannot find symbol
            Spannable spannableBody = new SpannableString(notification.getBody());
            ^
  symbol:   class Spannable
  location: class NotificationServiceExtension
D:\caps\cdis\android\app\src\main\java\com\bonfire\cdis\NotificationServiceExtension.java:30: error: cannot find symbol
            Spannable spannableBody = new SpannableString(notification.getBody());
                                          ^
  symbol:   class SpannableString
  location: class NotificationServiceExtension
D:\caps\cdis\android\app\src\main\java\com\bonfire\cdis\NotificationServiceExtension.java:31: error: cannot find symbol
            spannableBody.setSpan(new ForegroundColorSpan(Color.BLUE),0,notification.getBody().length(),0);
                                      ^
  symbol:   class ForegroundColorSpan
  location: class NotificationServiceExtension
D:\caps\cdis\android\app\src\main\java\com\bonfire\cdis\NotificationServiceExtension.java:31: error: cannot find symbol
            spannableBody.setSpan(new ForegroundColorSpan(Color.BLUE),0,notification.getBody().length(),0);
                                                          ^
  symbol:   variable Color
  location: class NotificationServiceExtension
9 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 7s
Exception: Gradle task assembleDebug failed with exit code 1

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions