2

Just updated the app to API 27 and added com.urbanairship.android:urbanairship-gcm:9.1.0 to build.gradle file. I can receive push notifications on Android N and below but doesn't work when triying on Android O and above, I already assigned a channel to notifications but it still not works here's what the code for AutoPilot looks like:

public class UrbanAirshipAutoPilot extends AutoPilot {

  @Override
  public void onAirshipReady(@NonNull UAirship airship) {
      airship.getPushManager().setUserNotificationsEnabled(true);

      // Android O
      if (Build.VERSION.SDK_INT >= 26) {
          Context context = UAirship.getApplicationContext();
          NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

          NotificationChannel channel = new NotificationChannel(UAConstants.DEFAULT_CHANNEL,
                  context.getString(R.string.custom_channel_name,
                  NotificationManager.IMPORTANCE_DEFAULT);

          notificationManager.createNotificationChannel(channel);
      }
      airship.getPushManager().setPushEnabled(true);
      airship.getPushManager().setUserNotificationsEnabled(true);

  }

  @Override
  public AirshipConfigOptions createAirshipConfigOptions(@NonNull Context context) {
      AirshipConfigOptions options = new AirshipConfigOptions.Builder()
          .setDevelopmentAppKey(UAConstants.DEV_PROD_KEY)
          .setDevelopmentAppSecret(UAConstants.DEV_SECRET_KEY)
          .setProductionAppKey(UAConstants.PROD_APP_KEY)
          .setProductionAppSecret(UAConstants.PROD_SECRET_KEY)
          .setFcmSenderId(UAConstants.GCM_PROJECT_ID)
          .setNotificationIcon(R.drawable.ic_notification)
          .setNotificationAccentColor(ContextCompat(getContext(), R.color.accent))
          .setNotificationChannel(UAConstants.DEFAULT_CHANNEL)
          .build();

      return options;
  }
}

I also added the AutoPilot to Manifest and it gets called it seems to be working and initializing correctly on any android version but for some reason notification don't arrive on Android O.

Also we are still using GCM at the moment

Daniel Moreno
  • 128
  • 1
  • 9

1 Answers1

1

We are seeing the same issue with Urban Airship and GCM. We've now tested using Firebase with Urban Airship, and now notifications seem to work.

Because of other related questions like here, I would guess the problem is not with Urban Airship, but in Android where GCM is simply buggy and it won't get fixed because it's deprecated.

Johan Paul
  • 2,203
  • 2
  • 22
  • 38
  • Thanks for sharing that information, we actually are looking forward to do the same I've tried everything else and nothing seemed to work. – Daniel Moreno Jan 25 '19 at 01:05