OneSignal / OneSignal-Flutter-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal
https://www.onesignal.com
Other
620 stars 212 forks source link

Can't use service extensions #192

Closed MrTarantula closed 4 years ago

MrTarantula commented 4 years ago

Description:

I have installed the SDK and it works. I then followed the instructions to add the notification extender service in Android.

Environment

  1. Latest OneSignal SDK (2.3.1)
  2. Added through pubspec.yaml
  3. OneSignal works without extension

Steps to Reproduce Issue:

  1. Install OneSignal in pubspec.yaml
  2. Follow instructions to setup SDK
  3. Add example service extension

Anything else:

[+25628 ms] C:\Users\me\myapp\android\app\src\main\java\com\myorg\myapp\MyNotifications.java:6: error: cannot find symbol
[   +1 ms]    protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
[        ]                                               ^
[        ]   symbol:   class OSNotificationReceivedResult
[        ]   location: class MyNotifications
[        ] 1 error
[  +77 ms] FAILURE: Build failed with an exception.
[        ] * What went wrong:
[        ] Execution failed for task ':app:compileDevDebugJavaWithJavac'.
[        ] > 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 25s
Gradle task assembleDevDebug failed with exit code 1
Exited (sigterm)
MrTarantula commented 4 years ago

I figured it out. It looks like the examples omit several needed imports, along with being outdated (no AndroidX). I use VS Code with no Java extensions installed so I wasn't getting the errors. I opened in Android Studio and immediately got reference errors. An update to step 3 of the instructions would look something like this:

package com.myorg.myapp;

import androidx.core.app.NotificationCompat;
import com.onesignal.OSNotificationDisplayedResult;
import com.onesignal.OSNotificationReceivedResult;
import com.onesignal.NotificationExtenderService;
import java.math.BigInteger;

public class NotificationExtenderExample extends NotificationExtenderService {
   @Override
   protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
      OverrideSettings overrideSettings = new OverrideSettings();
      overrideSettings.extender = new NotificationCompat.Extender() {
         @Override
         public NotificationCompat.Builder extend(NotificationCompat.Builder builder) {
            // Sets the background notification color to Green on Android 5.0+ devices.
            return builder.setColor(new BigInteger("FF00FF00", 16).intValue());
         }
      };

      OSNotificationDisplayedResult displayedResult = displayNotification(overrideSettings);
      //Log.d("OneSignalExample", "Notification displayed with id: " + displayedResult.androidNotificationId);

      return true;
   }
}
ajonno commented 4 years ago

brilliant thank you

mikechoch commented 4 years ago

Closing as @MrTarantula figured out it

MohitGupta121 commented 3 years ago

Same issue but my this import com.onesignal.NotificationExtenderService; Not not fixed, its showing error And all other onsignal. Objects I try latest dependency of Onsignal, old and from documentation but its still not fixed.

What I'll do please help to resolve this