QuickBlox / quickblox-android-sdk

QuickBlox Android SDK includes code snippets with main use cases and framework JAR library.
BSD 3-Clause "New" or "Revised" License
417 stars 697 forks source link

How to check if user is logged in? #608

Closed mechaadi closed 6 years ago

mechaadi commented 6 years ago

How can I check if the user is logged in or not? here is my code.

package com.example.acer.videochattry;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TimePicker;
import android.widget.Toast;

import com.quickblox.auth.session.QBSession;
import com.quickblox.auth.session.QBSessionManager;
import com.quickblox.auth.session.QBSessionParameters;
import com.quickblox.auth.session.QBSettings;
import com.quickblox.core.QBEntityCallback;
import com.quickblox.core.exception.QBResponseException;
import com.quickblox.users.QBUsers;
import com.quickblox.users.model.QBUser;
import com.quickblox.videochat.webrtc.QBRTCSession;

public class LoginActivity extends AppCompatActivity {

static final String APP_ID = "my app id";
static final String AUTH_KEY = "my auth key";
static final String AUTH_SECRET = "my auth secret";
static final String ACCOUNT_KEY = "my account key";

private EditText loginId, passwordL;
private Button loginbtn, signupbtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    QBSettings.getInstance().init(this,
            APP_ID,
            AUTH_KEY,
            AUTH_SECRET);

    QBSettings.getInstance().setAccountKey(ACCOUNT_KEY);

    if (checkSignIn()) {
        Toast.makeText(getApplicationContext(), "user is logged in", Toast.LENGTH_SHORT).show();
        startActivity(new Intent(LoginActivity.this, UsersActivity.class));
    }
    else {
        Toast.makeText(getApplicationContext(), "user is not logged in", Toast.LENGTH_SHORT).show();
        startActivity(new Intent(LoginActivity.this, MainActivity.class));
    }
    loginId = (EditText)findViewById(R.id.loginL);
    passwordL = (EditText)findViewById(R.id.passwordL);
    loginbtn = (Button) findViewById(R.id.loginBtn);
    signupbtn = (Button) findViewById(R.id.signupbtn);
    final boolean checksignin ;
    final QBUser qbUser = new QBUser();

    QBSessionManager.getInstance().init(getApplicationContext());

    loginbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
          qbUser.setLogin(loginId.getText().toString());
          qbUser.setPassword(passwordL.getText().toString());

            QBUsers.signIn(qbUser).performAsync(new QBEntityCallback<QBUser>() {
                @Override
                public void onSuccess(QBUser qbUser, Bundle bundle) {

                }

                @Override
                public void onError(QBResponseException e) {

                }
            });
        }
    });

    signupbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(LoginActivity.this, MainActivity.class));
        }
    });

 }

 private boolean checkSignIn() {
    return QBSessionManager.getInstance().getSessionParameters() != null;
 }
}
mechaadi commented 6 years ago

closing this issue