Xamarin.android Default FirebaseApp is not initialized in this process

Viewed 6163

I face issue with get token from firebase (push notification)

Default FirebaseApp is not initialized in this process com.ready_apps.Nebka.Business. Make sure to call FirebaseApp.initializeApp(Context) first.

even I called FirebaseApp.InitializeApp(this); in many places

MyApplication (that extend Application) , in onCreate of Activity where I call FirebaseInstanceId.Instance?.Token;

3 Answers

I didnt fix it but I find walkaround this issue in debug mode only

I called this method onCreate() in activit I need to request the token

FirebaseInstanceId.Instance?.Token

here is the method

private void ConfigureFireBase()
        {

#if DEBUG
            try
            {
            Task.Run(() =>
            {
                var instanceId = FirebaseInstanceId.Instance;
                instanceId?.DeleteInstanceId();
                //Log.Debug("TAG", "{0} {1}", instanceId?.Token?.ToString(), instanceId.GetToken(GetString(Resource.String.gcm_defaultSenderId), Firebase.Messaging.FirebaseMessaging.InstanceIdScope));

            });

             // For debug mode only - will accept the HTTPS certificate of Test/Dev server, as the HTTPS certificate is invalid /not trusted
            ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;
            }catch (Exception e)
            {
                Log.Debug("TAG", e.Message);
            }
#endif
        }
Related