android - Xamarin,火力地堡 : "Default FirebaseApp is not initialized in this process" - though initializeApp() is called?

标签 android firebase xamarin

我开始为那条线发疯:

Java.Lang.IllegalStateException:默认 FirebaseApp 未在此过程中初始化 com.TalkAboutTv.TalkAboutTv。确保先调用 FirebaseApp.initializeApp(Context)。

我不知道是什么原因造成的。我正在调用 FirebaseApp.IntApp(this) 并且我的包名称匹配......为什么它不起作用?

protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
    base.OnActivityResult(requestCode, resultCode, data);
}



protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);
    SetContentView (Resource.Layout.Main);

    firebase = new FirebaseClient("2131099704");
    Firebase.FirebaseApp.InitializeApp(this);

    FirebaseDatabase.Instance.GetReference("chats").AddValueEventListener(this);

    fab = FindViewById<Button>(Resource.Id.fab);
    edtChat = FindViewById<EditText>(Resource.Id.input);
    lstChat = FindViewById<ListView>(Resource.Id.list_of_messages);


    fab.Click += delegate
    {

        PostMessage();
    };



    if (FirebaseAuth.Instance.CurrentUser == null)
        StartActivityForResult(new Android.Content.Intent(this, typeof(SignIn)), MyResultCode);
    else
    {
        Toast.MakeText(this, "Welcome " + FirebaseAuth.Instance.CurrentUser.Email, ToastLength.Short).Show();
        DisplayChatMessage();
    }
}

private async void PostMessage()
{
    var items = await firebase.Child("chats").PostAsync(new MessageContent(FirebaseAuth.Instance.CurrentUser.Email, edtChat.Text));
    edtChat.Text = "";
}

public void OnCancelled(DatabaseError error)
{

}

public void OnDataChange(DataSnapshot snapshot)
{
    DisplayChatMessage();
}

private async void DisplayChatMessage()
{
    lstMessage.Clear();
    var items = await firebase.Child("chats")
        .OnceAsync<MessageContent>();

    foreach (var item in items)
        lstMessage.Add(item.Object);
    ListViewAdapter adapter = new ListViewAdapter(this, lstMessage);
    lstChat.Adapter = adapter;
    }
}

最佳答案

尝试在您的应用程序类(OnCreate 方法)中初始化 firebase。 但首先从项目控制台下载 google-services.json 文件,并确保它具有“GoogleServicesJson”值作为构建操作。

关于android - Xamarin,火力地堡 : "Default FirebaseApp is not initialized in this process" - though initializeApp() is called?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44437005/

相关文章:

ios - Binary Rejected 用于导入 Health 工具包但未实现/使用该工具包

ios - Xamarin.iOS 10.14/.NET Standard 2.0 支持哪些版本的 iOS?

c# - 如何在 Xamarin 应用程序和 Java Android 应用程序之间共享 sqlite 数据库

android - Acra 在发行版中不起作用

android - 如何在 web-view 的 Touchselect 上复制文本并在 android 中显示

firebase - 定价 : is multiple field changes in a firestore document cache seen as a single write when device is online?

javascript - Firebase:函数返回未定义、预期的 Promise 或值

Android 10 (Q) Fragment with RecyclerView transition shared element view 卡在固定位置

android - java.text.parseException : Unparseable date : 2020-02-06T08:00:00

android - FCM token 何时到期?