OneSignal - ANDROID - NotificationExtenderService

后端 未结 1 1298
一生所求
一生所求 2021-01-22 07:42

I\'m having problems since a week ago with OneSignal and doing stuff when I tap on the notification when my app is killed. After research, I\'ve found out that my p

相关标签:
1条回答
  • 2021-01-22 08:27

    You can just put it in a separate file specifically for that class. For example...

    NotificationExtenderExample.java

    import android.support.v4.app.NotificationCompat;
    import com.onesignal.OSNotificationPayload;
    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;
       }
    }
    

    Then, add the following to your AndroidManifest.xml

    <service
       android:name=".YOUR_CLASS_NAME"
       android:permission="android.permission.BIND_JOB_SERVICE"
       android:exported="false">
       <intent-filter>
          <action android:name="com.onesignal.NotificationExtender" />
       </intent-filter>
    </service>
    

    SOURCE: https://documentation.onesignal.com/docs/service-extensions#section-notification-extender-service-span-class-label-all-label-android-android-span-

    0 讨论(0)
提交回复
热议问题