//Checks to see if the SDK is connected to Layer and whether a user is authenticated
        //The respective callbacks are executed in MyConnectionListener and MyAuthenticationListener
        private void _LoadLayerClient()
        {
            // Check if Sample App is using a valid app ID.
            if (_IsValidAppID())
            {
                if (layerClient == null)
                {
                    //Used for debugging purposes ONLY. DO NOT include this option in Production Builds.
                    LayerClient.SetLoggingEnabled(this.ApplicationContext, true);

                    // Initializes a LayerClient object with the Google Project Number
                    LayerClient.Options options = new LayerClient.Options();

                    //Sets the GCM sender id allowing for push notifications
                    options.InvokeGoogleCloudMessagingSenderId(GCM_PROJECT_NUMBER);

                    //By default, only unread messages are synced after a user is authenticated, but you
                    // can change that behavior to all messages or just the last message in a conversation
                    options.InvokeHistoricSyncPolicy(LayerClient.Options.HistoricSyncPolicy.AllMessages);


                    layerClient = LayerClient.NewInstance(this, LAYER_APP_ID, options);

                    //Register the connection and authentication listeners
                    layerClient.RegisterConnectionListener(connectionListener);
                    layerClient.RegisterAuthenticationListener(authenticationListener);
                }

                //Check the current state of the SDK. The client must be CONNECTED and the user must
                // be AUTHENTICATED in order to send and receive messages. Note: it is possible to be
                // authenticated, but not connected, and vice versa, so it is a best practice to check
                // both states when your app launches or comes to the foreground.
                if (!layerClient.IsConnected)
                {
                    //If Layer is not connected, make sure we connect in order to send/receive messages.
                    // MyConnectionListener.java handles the callbacks associated with Connection, and
                    // will start the Authentication process once the connection is established
                    layerClient.Connect();
                }
                else if (!layerClient.IsAuthenticated)
                {
                    //If the client is already connected, try to authenticate a user on this device.
                    // MyAuthenticationListener.java handles the callbacks associated with Authentication
                    // and will start the Conversation View once the user is authenticated
                    layerClient.Authenticate();
                }
                else
                {
                    // If the client is to Layer and the user is authenticated, start the Conversation
                    // View. This will be called when the app moves from the background to the foreground,
                    // for example.
                    OnUserAuthenticated();
                }
            }
        }
Пример #2
0
        public static IAuthenticationProvider GetAuthenticationProvider()
        {
            if (sAuthProvider == null)
            {
                sAuthProvider = sFlavor.GenerateAuthenticationProvider(sInstance);

                // If we have cached credentials, try authenticating with Layer
                LayerClient layerClient = GetLayerClient();
                if (layerClient != null && sAuthProvider.HasCredentials())
                {
                    layerClient.Authenticate();
                }
            }
            return(sAuthProvider);
        }
        //Called on connection success. The Quick Start App immediately tries to
        //authenticate a user (or, if a user is already authenticated, return to the conversation
        //screen).
        public void OnConnectionConnected(LayerClient client)
        {
            Log.Verbose(TAG, "Connected to Layer");

            //If the user is already authenticated (and this connection was being established after
            // the app was disconnected from the network), then start the conversation view.
            //Otherwise, start the authentication process, which effectively "logs in" a user
            if (client.IsAuthenticated)
            {
                main_activity.OnUserAuthenticated();
            }
            else
            {
                client.Authenticate();
            }
        }
        protected override void OnResume()
        {
            base.OnResume();
            LayerClient client = App.GetLayerClient();

            if (client == null)
            {
                return;
            }
            if (client.IsAuthenticated)
            {
                client.Connect();
            }
            else
            {
                client.Authenticate();
            }
        }
Пример #5
0
 public bool RouteLogin(LayerClient layerClient, string layerAppId, Activity from)
 {
     if (layerAppId == null)
     {
         // No App ID: must scan from QR code.
         if (Log.IsLoggable(Log.VERBOSE))
         {
             Log.v("Routing to QR Code scanning Activity");
         }
         Intent intent = new Intent(from, typeof(DemoAtlasIdScannerActivity));
         intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.ClearTask | ActivityFlags.NewTask);
         from.StartActivity(intent);
         return(true);
     }
     if (layerClient != null && !layerClient.IsAuthenticated)
     {
         if (HasCredentials())
         {
             // Use the cached AuthenticationProvider credentials to authenticate with Layer.
             if (Log.IsLoggable(Log.VERBOSE))
             {
                 Log.v("Using cached credentials to authenticate");
             }
             layerClient.Authenticate();
         }
         else
         {
             // App ID, but no user: must authenticate.
             if (Log.IsLoggable(Log.VERBOSE))
             {
                 Log.v("Routing to login Activity");
             }
             Intent intent = new Intent(from, typeof(DemoLoginActivity));
             intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.ClearTask | ActivityFlags.NewTask);
             from.StartActivity(intent);
             return(true);
         }
     }
     if (Log.IsLoggable(Log.VERBOSE))
     {
         Log.v("No authentication routing needed");
     }
     return(false);
 }
Пример #6
0
        /**
         * Authenticates with the AuthenticationProvider and Layer, returning asynchronous results to
         * the provided callback.
         *
         * @param credentials Credentials associated with the current AuthenticationProvider.
         * @param callback    Callback to receive authentication results.
         */
        public static void Authenticate(Object credentials, IAuthenticationProviderCallback callback)
        {
            LayerClient client = GetLayerClient();

            if (client == null)
            {
                return;
            }
            String layerAppId = GetLayerAppId();

            if (layerAppId == null)
            {
                return;
            }
            GetAuthenticationProvider()
            .SetCredentials(credentials)
            .SetCallback(callback);
            client.Authenticate();
        }
 public void OnConnectionConnected(LayerClient client)
 {
     // Ask the LayerClient to authenticate. If no auth credentials are present,
     // an authentication challenge is issued
     client.Authenticate();
 }