Ejemplo n.º 1
0
        // OnHandleIntent is invoked on a worker thread:
        protected override void OnHandleIntent(Intent intent)
        {
            try
            {
                Log.Info("RegistrationIntentService", "Calling InstanceID.GetAuthToken");
                //FirebaseApp.InitializeApp(this);
                // Ensure that the request is atomic:
                lock (this)
                {
                    // Request a registration token:
                    var instanceID = InstanceID.GetInstance(this);
                    var token      = instanceID.GetToken("509579216493", GoogleCloudMessaging.InstanceIdScope, null);
                    //Toast.MakeText(this, token, ToastLength.Short).Show();
                    // Log the registration token that was returned from GCM:
                    Log.Info("RegistrationIntentService", "GCM Registration Token: " + token);
                    CurrentUser.PutDeviceToken(token);
                    // Send to the app server (if it requires it):
                    //SendRegistrationToAppServer(token);

                    //FirebaseMessaging.Instance.SubscribeToTopic("global");
                    // Subscribe to receive notifications:
                    SubscribeToTopics(token, Topics);
                }
            }
            catch (Exception e)
            {
                Log.Debug("RegistrationIntentService", "Failed to get a registration token", e.Message);
            }
        }