本文整理匯總了Java中com.google.firebase.auth.FirebaseAuth.AuthStateListener方法的典型用法代碼示例。如果您正苦於以下問題:Java FirebaseAuth.AuthStateListener方法的具體用法?Java FirebaseAuth.AuthStateListener怎麽用?Java FirebaseAuth.AuthStateListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.firebase.auth.FirebaseAuth
的用法示例。
在下文中一共展示了FirebaseAuth.AuthStateListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: subscribe
import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override public void subscribe(final ObservableEmitter<FirebaseAuth> emitter) {
final FirebaseAuth.AuthStateListener listener = new FirebaseAuth.AuthStateListener() {
@Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if (!emitter.isDisposed()) {
emitter.onNext(firebaseAuth);
}
}
};
instance.addAuthStateListener(listener);
emitter.setDisposable(Disposables.fromAction(new Action() {
@Override public void run() throws Exception {
instance.removeAuthStateListener(listener);
}
}));
}
示例2: onCreate
import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fbAuth = FirebaseAuth.getInstance();
fbUser = FirebaseAuth.getInstance().getCurrentUser();
authStateListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if (fbUser == null){
Log.v("FIREBASE", "--Logout");
}
}
};
//register("[email protected]", "makunat10");
//signIn("[email protected]", "makunat10");
}
示例3: init
import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
public void init() {
// Initialize listener.
// ...
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
Utils.d("E&P:onAuthStateChanged:signed_in:" + user.getUid());
successSignIn(user);
} else {
// User is signed out
Utils.d("E&P:onAuthStateChanged:signed_out");
successSignOut();
}
// update user details;
}
};
}
示例4: onCreateView
import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.frag_request,container,false);
mRequests = new ArrayList<>();
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
mUser = firebaseAuth.getCurrentUser();
}
};
//mRequests.add(new Request("Name1","9PM"));
//mRequests.add(new Request("Name2","9PM"));
//mRequests.add(new Request("Name3","9PM"));
initViews();
setUpRecyclerView();
getRequests();
return mView;
}
示例5: initFirebase
import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
private void initFirebase() {
//Khoi tao thanh phan de dang nhap, dang ky
mAuth = FirebaseAuth.getInstance();
authUtils = new AuthUtils();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
StaticConfig.UID = user.getUid();
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
if (firstTimeAccess) {
startActivity(new Intent(LoginActivity.this, HomeActivity.class));
LoginActivity.this.finish();
}
} else {
Log.d(TAG, "onAuthStateChanged:signed_out");
}
firstTimeAccess = false;
}
};
//Khoi tao dialog waiting khi dang nhap
waitingDialog = new LovelyProgressDialog(this).setCancelable(false);
}
示例6: authListener
import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override
public void authListener(final OnLoginFinishedListener listener){
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
user = firebaseAuth.getCurrentUser();
if (user != null) {
if(signInWithGoogle){
listener.onLoginGoogleSuccess();
}
else if(registerWithMail){
listener.onRegisterMailSuccess();
}
else {
listener.onLoginMailSuccess();
}
} else {
// User is signed out
// Log.d(TAG, "onAuthStateChanged:signed_out");
}
}
};
}
示例7: initializeFirebaseAuth
import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
private void initializeFirebaseAuth() {
// Initialize Firebase Auth
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
// signOut();
}
}
};
}
示例8: registerFirebase
import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
protected void registerFirebase() {
firebaseListener =
new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
onLoginComplete();
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
}
};
}
示例9: init
import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
public void init() {
TwitterAuthConfig authConfig = new TwitterAuthConfig(
activity.getString(R.string.twitter_consumer_key),
activity.getString(R.string.twitter_consumer_secret));
Fabric.with(activity, new Twitter(authConfig));
mAuth = FirebaseAuth.getInstance();
twitterAuthClient = new TwitterAuthClient();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
for (UserInfo usr : user.getProviderData()) {
if (usr.getProviderId().equals("twitter.com")) {
Utils.d("Twitter:AuthStateChanged:signed_in:"+
user.getUid());
successSignIn(user);
}
}
} else {
// User is signed out
Utils.d("Twitter:onAuthStateChanged:signed_out");
successSignOut();
}
// update firebase auth dets.
}
};
onStart();
}
示例10: onCreate
import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
/**
* The activity launched
* @param savedInstanceState - current app state
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// init views
mSignInButton = findViewById(R.id.sign_in_button);
mSignInButton.setOnClickListener(this);
mProgressBar = findViewById(R.id.sign_in_progress);
mDatabase = DatabaseManager.getInstance();
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
/**
* Handle a change in user's sign in status
* @param firebaseAuth - the user's authentication
*/
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
}
else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
}
};
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail()
.requestIdToken(getString(R.string.default_web_client_id)).build();
// Build a GoogleApiClient with access to the Google Sign-In API and the options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
}
示例11: onCreate
import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation_drawer);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//redirect if user is null i.e not logged in or registered
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if(firebaseAuth.getCurrentUser()==null){
startActivity(new Intent(NavigationDrawerActivity.this, LoginPageActivity.class));
}
}
};
//set the initial fragment
HomeFragment homeFragment = new HomeFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, homeFragment);
fragmentTransaction.commit();
DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
View view = navigationView.getHeaderView(0);
//set email in navigation drawer
TextView navUserEmail = view.findViewById(R.id.nav_user_email);
navUserEmail.setText(mAuth.getCurrentUser().getEmail());
//set user name in navigation drawer
TextView navUserName = view.findViewById(R.id.nav_user_name);
navUserName.setText(mAuth.getCurrentUser().getDisplayName());
}
示例12: onCreate
import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int mUIFlag = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
getWindow().getDecorView().setSystemUiVisibility(mUIFlag);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
auth = FirebaseAuth.getInstance();
authListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
Log.d(TAG, "onAuthStateChanged:signed_out");
}
}
};
moveClouds();
}
示例13: onCreate
import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_auth);
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
startActivity(new Intent(AuthActivity.this, HomeActivity.class));
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
}
};
mGoogleSignIn = (SignInButton)findViewById(R.id.google_sign_in);
TextView buttonText = (TextView) mGoogleSignIn.getChildAt(0);
buttonText.setText(R.string.login_google);
mGoogleSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
signIn();
}
});
GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
.enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Toast.makeText(AuthActivity.this, "Coneccao Falhou",Toast.LENGTH_SHORT).show();
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
.build();
callbackManager = CallbackManager.Factory.create();
loginButton = (LoginButton) findViewById(R.id.loginButton);
loginButton.setReadPermissions(Arrays.asList("email"));
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
handleFacebookAccessToken(loginResult.getAccessToken());
}
@Override
public void onCancel() {
Toast.makeText(getApplicationContext(), R.string.cancel_login, Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException error) {
Toast.makeText(getApplicationContext(), R.string.error_login, Toast.LENGTH_SHORT).show();
}
});
}
示例14: onCreate
import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// LUKE - 12/9/17 - lock orientation to portrait mode
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_login);
// TODO: 10/31/17 JD update the ui function, modify layout to conform to material standards, welcome user already logged in
// Login form
mEmailField = (AutoCompleteTextView) findViewById(R.id.email);
mPasswordField = (EditText) findViewById(R.id.password);
//TODO 12/5/17 Remove prior to release
//For Testing
mEmailField.setText("[email protected]");
mPasswordField.setText("123456");
findViewById(R.id.email_sign_in_button).setOnClickListener(this);
// TODO: 12/5/17 KB implement logout procedure
findViewById(R.id.email_sign_out_button).setOnClickListener(this);
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
// This should change the display to 'logout' or 'change role'
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
// Default view.
// Pull the buttons, click listeners, and other setup in here.
}
// TODO: 11/18/17 JD what's the purpose behind the listenere beyond logging?
}
};
mAuth.addAuthStateListener(mAuthListener);
mAnalyticsInstance = FirebaseAnalytics.getInstance(this);
// mUserManager = new UserManager();
}
示例15: onCreate
import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.google_auth_api_key))
.requestEmail()
.build();
auth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener(){
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
final FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d("USER signed in", "onAuthStateChanged:signed_in:" + user.getUid());
database = FirebaseDatabase.getInstance().getReference();
database.child("users").child(user.getUid()).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(!dataSnapshot.exists()){
database.child("users").child(user.getUid())
.setValue(new User(user.getDisplayName()));
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else {
// User is signed out
Log.d("USER signed out", "onAuthStateChanged:signed_out");
}
}
};
// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
signInButton.setSize(SignInButton.SIZE_STANDARD);
findViewById(R.id.sign_in_button).setOnClickListener(this);
}