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);
        }
Exemplo n.º 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);
            Bootstrap.Begin(() => new DeviceInstallationService());

            if (DeviceInstallationService.NotificationsSupported)
            {
                FirebaseInstanceId.GetInstance(Firebase.FirebaseApp.Instance)
                .GetInstanceId()
                .AddOnSuccessListener(this);
            }

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            CurrentPlatform.Init();

            string dbName     = "smartsub_db.sqlite";
            string folderPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            string fullPath   = Path.Combine(folderPath, dbName);

            LoadApplication(new App(fullPath));
        }
Exemplo n.º 3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            if (PlayServicesAvailable)
            {
                FirebaseInstanceId.GetInstance(Firebase.FirebaseApp.Instance)
                .GetInstanceId()
                .AddOnSuccessListener(this);
            }

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

            Bootstrap.Begin(() => new DeviceInstallationService(
                                () => PushNotificationFirebaseMessagingService.Token,
                                () => PlayServicesAvailable,
                                () => GetPlayServicesError()));

            LoadApplication(new App());

            ProcessNotificationActions(Intent);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Bootstrap.Begin(() => new DeviceInstallationService());

            if (DeviceInstallationService.NotificationsSupported)
            {
                FirebaseInstanceId.GetInstance(Firebase.FirebaseApp.Instance)
                .GetInstanceId()
                .AddOnSuccessListener(this);
            }

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            Xamarin.Forms.Forms.Init(this, savedInstanceState);

            LoadApplication(new App());

            CreateNotificationChannel();

            if (!ShortcutBadger.IsBadgeCounterSupported(this))
            {
                Console.WriteLine("Pay attention: badge counter not supported");
            }
        }
Exemplo n.º 5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;
            base.Window.RequestFeature(WindowFeatures.ActionBar);
            base.SetTheme(Resource.Style.MainTheme);

            base.OnCreate(savedInstanceState);

            Bootstrap.Begin(() => new DeviceInstallationService());
            if (DeviceInstallationService.NotificationsSupported)
            {
                FirebaseInstanceId.GetInstance(Firebase.FirebaseApp.Instance)
                .GetInstanceId()
                .AddOnSuccessListener(this);
            }

            if (Intent.Extras != null)
            {
                foreach (var key in Intent.Extras.KeySet())
                {
                    if (key != null)
                    {
                        var value = Intent.Extras.GetString(key);
                        Log.Debug(TAG, "Key: {0} Value: {1}", key, value);
                    }
                }
            }

            IsPlayServicesAvailable();
            CreateNotificationChannel();

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            Xamarin.FormsMaps.Init(this, savedInstanceState);

            LoadApplication(new App());

            ProcessNotificationActions(Intent);
        }
Exemplo n.º 6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "Fcm" layout resource
            SetContentView(Resource.Layout.Fcm);
            this.WireUpViews();
            btnSubscribe.SetOnClickListener(this);
            btnLogToken.SetOnClickListener(this);

            // Setup our firebase options then init
            FirebaseOptions o = new FirebaseOptions.Builder()
                                .SetApiKey(GetString(Resource.String.ApiKey))
                                .SetApplicationId(GetString(Resource.String.ApplicationId))
                                .SetDatabaseUrl(GetString(Resource.String.DatabaseUrl))
                                .SetGcmSenderId(GetString(Resource.String.SenderId))
                                .Build();
            FirebaseApp fa = FirebaseApp.InitializeApp(this, o);

            // Get our instance ID
            mInstanceId = FirebaseInstanceId.GetInstance(fa);
        }