protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); // To use this you have to set up a project in the Firebase console and add the google-services.json file var baseOptions = FirebaseOptions.FromResource(Application.Context); var options = new FirebaseOptions.Builder(baseOptions) .SetProjectId(baseOptions.StorageBucket.Split('.')[0]) .Build(); var fa = FirebaseApp.InitializeApp(Application.Context, options, "Xamarin"); //FirebaseApp fa = FirebaseApp.InitializeApp(Application.Context); mAuth = FirebaseAuth.GetInstance(fa); if (mAuth == null) { Console.WriteLine("mAuth is null"); } AuthCredential credential = EmailAuthProvider.GetCredential("*****@*****.**", "password"); var creds = mAuth.SignInWithEmailAndPassword("*****@*****.**", "password"); // Here the program crashes due to a null mAuth }
public string TryForceTokenRefresh(string senderId) { string token = null; try { FirebaseApp firebaseApp = FirebaseApp.Instance; if (firebaseApp == null) { firebaseApp = FirebaseApp.InitializeApp(Application.Context, FirebaseOptions.FromResource(Application.Context)); } FirebaseInstanceId firebaseInstanceId = FirebaseInstanceId.Instance; if (firebaseInstanceId == null && firebaseApp != null) { firebaseInstanceId = FirebaseInstanceId.GetInstance(firebaseApp); } if (firebaseInstanceId != null && firebaseApp != null) { /// should force token to be refreshed firebaseInstanceId.DeleteInstanceId(); token = FirebaseInstanceId.GetInstance(firebaseApp)?.GetToken(senderId, "FCM"); } } catch { } return(token); }
public static void Init(Android.Content.Context context) { var baseOptions = FirebaseOptions.FromResource(context); // This HACK will be not needed, fixed in https://github.com/xamarin/GooglePlayServicesComponents/commit/723ebdc00867a4c70c51ad2d0dcbd36474ce8ff1 var options = new FirebaseOptions.Builder(baseOptions).SetProjectId(baseOptions.StorageBucket.Split('.')[0]).Build(); app = FirebaseApp.InitializeApp(context, options, AppName); }