【问题标题】:Urban Airship Android GCM not receiving push notifications on Android Oreo and PieUrban Airship Android GCM 在 Android Oreo 和 Pie 上未收到推送通知
【发布时间】:2018-10-24 20:01:49
【问题描述】:

刚刚将应用更新到 API 27 并将 com.urbanairship.android:urbanairship-gcm:9.1.0 添加到 build.gradle 文件中。我可以在 Android N 及更低版本上接收推送通知,但在尝试在 Android O 及更高版本上时不起作用,我已经为通知分配了一个通道,但它仍然不起作用这是 AutoPilot 的代码:

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;
  }
}

我还将 AutoPilot 添加到 Manifest 并被调用,它似乎在任何 android 版本上都能正常工作和初始化,但由于某种原因,通知没有到达 Android O。

另外,我们目前仍在使用 GCM

【问题讨论】:

    标签: android google-cloud-messaging android-8.0-oreo urbanairship.com


    【解决方案1】:

    我们在 Urban Airship 和 GCM 上看到了同样的问题。我们现在已经在 Urban Airship 上使用 Firebase 进行了测试,现在通知似乎可以工作了。

    由于 here 等其他相关问题,我猜想问题不在于 Urban Airship,而是在 Android 中,GCM 存在错误并且由于已被弃用而无法修复。

    【讨论】:

    • 感谢分享这些信息,我们实际上期待着做同样的事情,我已经尝试了其他所有方法,但似乎没有任何效果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多