【问题标题】:Overwrite DefaultInstance of the firebase app. Re-initialize: java.lang.IllegalStateException: FirebaseApp was deleted覆盖 Firebase 应用的 DefaultInstance。重新初始化:java.lang.IllegalStateException:FirebaseApp 被删除
【发布时间】:2022-01-08 19:29:13
【问题描述】:

我想在初始化后更改 FirebaseApp 配置,但出现错误 - “java.lang.IllegalStateException: FirebaseApp was deleted”

        var apps = FirebaseApp.GetApps(Context);
        if (apps.Count != 0 )
        {
            apps.Where((i) => i.Name == FirebaseApp.DefaultAppName).FirstOrDefault().Delete();
        }
        var options = new FirebaseOptions.Builder()
            .SetApiKey(config["API_KEY"])
            .SetApplicationId(config["GOOGLE_APP_ID"])
            .SetGcmSenderId(config["GCM_SENDER_ID"])
            .SetProjectId(config["PROJECT_ID"])
            .SetStorageBucket(config["STORAGE_BUCKET"])
            .Build();

            FirebaseApp.InitializeApp(Context, options);

       if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                //Change for your default notification channel id here
                FirebasePushNotificationManager.DefaultNotificationChannelId = "FirebasePushNotificationChannel";

                //Change for your default notification channel name here
                FirebasePushNotificationManager.DefaultNotificationChannelName = "General";

                FirebasePushNotificationManager.DefaultNotificationChannelImportance = NotificationImportance.Max;
            }

       FirebasePushNotificationManager.Initialize(Context, false);

如何解决?

【问题讨论】:

    标签: c# android firebase firebase-cloud-messaging


    【解决方案1】:

    修复 - 已删除令牌和我们 Xamarin.Firebase.Messaging 代替 PluginFirebasePushNotifications

     public async Task<bool> TryDeleteFirebaseAppAsync(string name)
        {
            var apps = FirebaseApp.GetApps(this);
            if (apps.Count != 0)
            {
                var app = apps.Where((i) => i.Name == name).FirstOrDefault();
                await FirebaseMessaging.Instance.DeleteToken();
                app.Delete();
                return true;
            }
            else
                return false;
    
        }
    

    我的样本:FirebaseTestNotification

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-23
      • 2012-10-22
      相关资源
      最近更新 更多