Java Code Examples for com.google.firebase.auth.FirebaseAuth#getInstance()
The following examples show how to use
com.google.firebase.auth.FirebaseAuth#getInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EasyFirebaseAuth.java From EasyFirebase with Apache License 2.0 | 6 votes |
public EasyFirebaseAuth(GoogleApiClient googleApiClient) { mAuth = FirebaseAuth.getInstance(); this.googleApiClient = googleApiClient; mAuthListener = new FirebaseAuth.AuthStateListener() { @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { final FirebaseUser user = firebaseAuth.getCurrentUser(); if (user != null) { if (firebaseUserSubscriber != null) { firebaseUserSubscriber.onNext(new Pair<GoogleSignInAccount, FirebaseUser>(googleSignInAccount, user)); firebaseUserSubscriber.onCompleted(); } if (loggedSubcriber != null) { loggedSubcriber.onNext(user); } // User is signed in Log.d("TAG", "onAuthStateChanged:signed_in:" + user.getUid()); } else { // User is signed out Log.d("TAG", "onAuthStateChanged:signed_out"); } } }; }
Example 2
Source File: firebaseutils.java From LuxVilla with Apache License 2.0 | 6 votes |
public static void setuserfirstdata(final Context context, String username){ FirebaseAuth auth=FirebaseAuth.getInstance(); FirebaseUser user = auth.getCurrentUser(); UserProfileChangeRequest.Builder builder = new UserProfileChangeRequest.Builder(); builder.setDisplayName(username); if (user !=null){ user.updateProfile(builder.build()).addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (!task.isSuccessful()){ Toast.makeText(context,"Ocorreu um erro",Toast.LENGTH_LONG).show(); } } }); } }
Example 3
Source File: AuthTest.java From gdx-fireapp with Apache License 2.0 | 6 votes |
@Test public void signInAnonymously() { // Given Auth auth = new Auth(); Consumer consumer = Mockito.mock(Consumer.class); Mockito.when(task.isSuccessful()).thenReturn(true); Mockito.doReturn(task).when(firebaseAuth).signInAnonymously(); // When auth.signInAnonymously() .then(consumer); // Then PowerMockito.verifyStatic(FirebaseAuth.class, VerificationModeFactory.times(2)); FirebaseAuth.getInstance(); Mockito.verify(firebaseAuth, VerificationModeFactory.times(1)).signInAnonymously(); Mockito.verify(task, VerificationModeFactory.times(1)).addOnCompleteListener(Mockito.any(OnCompleteListener.class)); Mockito.verify(consumer, VerificationModeFactory.times(1)).accept(Mockito.any(GdxFirebaseUser.class)); Mockito.verify(firebaseAuth, VerificationModeFactory.times(1)).getCurrentUser(); }
Example 4
Source File: FirestoreTest.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
@Test public void setShouldFailWithPermissionDenied() throws Exception { FirebaseAuth auth = FirebaseAuth.getInstance(); FirebaseFirestore firestore = FirebaseFirestore.getInstance(); auth.signOut(); Thread.sleep(1000); // TODO(allisonbm92): Introduce a better means to reduce flakes. DocumentReference doc = firestore.collection("restaurants").document(TestId.create()); try { HashMap<String, Object> data = new HashMap<>(); data.put("popularity", 5000L); Task<?> setTask = doc.set(new HashMap<>(data)); Throwable failure = Tasks2.waitForFailure(setTask); FirebaseFirestoreException ex = (FirebaseFirestoreException) failure; assertThat(ex.getCode()).isEqualTo(FirebaseFirestoreException.Code.PERMISSION_DENIED); } finally { Tasks2.waitBestEffort(doc.delete()); } }
Example 5
Source File: firebaseutils.java From LuxVilla with Apache License 2.0 | 6 votes |
public static void setbio(final TextView bio){ FirebaseAuth auth=FirebaseAuth.getInstance(); FirebaseUser user=auth.getCurrentUser(); FirebaseDatabase database = FirebaseDatabase.getInstance(); if (user !=null){ DatabaseReference myRef = database.getReference("users").child(user.getUid()).child("user_bio"); myRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()){ bio.setText(dataSnapshot.getValue(String.class)); } } @Override public void onCancelled(DatabaseError databaseError) { } }); } }
Example 6
Source File: AuthTest.java From gdx-fireapp with Apache License 2.0 | 6 votes |
@Test public void signInWithToken() { // Given Auth auth = new Auth(); Consumer consumer = Mockito.mock(Consumer.class); Mockito.when(task.isSuccessful()).thenReturn(true); Mockito.doReturn(task).when(firebaseAuth).signInWithCustomToken(Mockito.anyString()); // When auth.signInWithToken("token") .then(consumer); // Then PowerMockito.verifyStatic(FirebaseAuth.class, VerificationModeFactory.times(2)); FirebaseAuth.getInstance(); Mockito.verify(firebaseAuth, VerificationModeFactory.times(1)).signInWithCustomToken(Mockito.eq("token")); Mockito.verify(firebaseAuth, VerificationModeFactory.times(1)).getCurrentUser(); Mockito.verify(task, VerificationModeFactory.times(1)).addOnCompleteListener(Mockito.any(OnCompleteListener.class)); Mockito.verify(consumer, VerificationModeFactory.times(1)).accept(Mockito.any(GdxFirebaseUser.class)); }
Example 7
Source File: TripHistory.java From UberClone with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_trip_history); initToolbar(); initRecyclerView(); mAuth = FirebaseAuth.getInstance(); database = FirebaseDatabase.getInstance(); riderHistory = database.getReference(Common.history_driver); listData = new ArrayList<>(); adapter = new historyAdapter(this, listData, new ClickListener() { @Override public void onClick(View view, int index) { } }); rvHistory.setAdapter(adapter); getHistory(); }
Example 8
Source File: SignInActivity.java From jterm-cswithandroid with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sign_in); // Assign fields mSignInButton = (SignInButton) findViewById(R.id.sign_in_button); // Set click listeners mSignInButton.setOnClickListener(this); // Configure Google Sign In GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.default_web_client_id)) .requestEmail() .build(); mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); // Initialize FirebaseAuth mFirebaseAuth = FirebaseAuth.getInstance(); }
Example 9
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 5 votes |
public void sendEmailVerificationWithContinueUrl() { // [START send_email_verification_with_continue_url] FirebaseAuth auth = FirebaseAuth.getInstance(); FirebaseUser user = auth.getCurrentUser(); String url = "http://www.example.com/verify?uid=" + user.getUid(); ActionCodeSettings actionCodeSettings = ActionCodeSettings.newBuilder() .setUrl(url) .setIOSBundleId("com.example.ios") // The default for this is populated with the current android package name. .setAndroidPackageName("com.example.android", false, null) .build(); user.sendEmailVerification(actionCodeSettings) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.d(TAG, "Email sent."); } } }); // [END send_email_verification_with_continue_url] // [START localize_verification_email] auth.setLanguageCode("fr"); // To apply the default app language instead of explicitly setting it. // auth.useAppLanguage(); // [END localize_verification_email] }
Example 10
Source File: ProductRecommentationActivity.java From FaceT with Mozilla Public License 2.0 | 5 votes |
private void setup() { getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle("Recommendation"); detectedRGBvalue = getIntent().getDoubleArrayExtra("detectedRGBvalue"); Log.d(TAG + " detectedRGBvalue ", detectedRGBvalue[0] + " , " + detectedRGBvalue[1] + " , " + detectedRGBvalue[2]); Typeface fontType = FontManager.getTypeface(getApplicationContext(), FontManager.APP_FONT); FontManager.markAsIconContainer(findViewById(R.id.activity_product_recommendation_layout), fontType); mAuth = FirebaseAuth.getInstance(); mDatabase = FirebaseDatabase.getInstance().getReference().child("Product"); mDatabase.keepSynced(true); mDatabaseUsers = FirebaseDatabase.getInstance().getReference().child("Users"); mDatabaseUsers.keepSynced(true); mDatabaseBrand = FirebaseDatabase.getInstance().getReference().child("Brand"); mDatabaseRatings = FirebaseDatabase.getInstance().getReference().child("Ratings"); mDatabaseRatings.keepSynced(true); mDatabaseMatch = FirebaseDatabase.getInstance().getReference().child("Match"); Log.d(TAG + "mDatabaseRatings", mDatabaseRatings.toString()); recommend_product_list_1 = (RecyclerView) findViewById(R.id.recommend_product_list_1); recommend_product_list_2 = (RecyclerView) findViewById(R.id.recommend_product_list_2); recommend_product_list_3 = (RecyclerView) findViewById(R.id.recommend_product_list_3); recommend_product_list_4 = (RecyclerView) findViewById(R.id.recommend_product_list_4); recommend_product_list_1.setItemAnimator(new DefaultItemAnimator()); recommend_product_list_2.setItemAnimator(new DefaultItemAnimator()); recommend_product_list_3.setItemAnimator(new DefaultItemAnimator()); recommend_product_list_4.setItemAnimator(new DefaultItemAnimator()); }
Example 11
Source File: firebaseutils.java From LuxVilla with Apache License 2.0 | 5 votes |
public static void removelike(String id){ String uid=""; FirebaseAuth auth=FirebaseAuth.getInstance(); FirebaseUser user=auth.getCurrentUser(); if (user != null){ uid=user.getUid(); } FirebaseDatabase database = FirebaseDatabase.getInstance(); DatabaseReference myRef = database.getReference("users").child(uid).child("likes"); myRef.child("heart"+id).removeValue(); }
Example 12
Source File: AuthOperationManager.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
private FirebaseAuth getScratchAuth(FlowParameters flowParameters) { // Use a different FirebaseApp so that the anonymous user state is not lost in our // original FirebaseAuth instance. if (mScratchAuth == null) { FirebaseApp app = FirebaseApp.getInstance(flowParameters.appName); mScratchAuth = FirebaseAuth.getInstance(getScratchApp(app)); } return mScratchAuth; }
Example 13
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 5 votes |
public void testPhoneAutoRetrieve() { // [START auth_test_phone_auto] // The test phone number and code should be whitelisted in the console. String phoneNumber = "+16505554567"; String smsCode = "123456"; FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(); FirebaseAuthSettings firebaseAuthSettings = firebaseAuth.getFirebaseAuthSettings(); // Configure faking the auto-retrieval with the whitelisted numbers. firebaseAuthSettings.setAutoRetrievedSmsCodeForPhoneNumber(phoneNumber, smsCode); PhoneAuthProvider phoneAuthProvider = PhoneAuthProvider.getInstance(); phoneAuthProvider.verifyPhoneNumber( phoneNumber, 60L, TimeUnit.SECONDS, this, /* activity */ new PhoneAuthProvider.OnVerificationStateChangedCallbacks() { @Override public void onVerificationCompleted(PhoneAuthCredential credential) { // Instant verification is applied and a credential is directly returned. // ... } // [START_EXCLUDE] @Override public void onVerificationFailed(FirebaseException e) { } // [END_EXCLUDE] }); // [END auth_test_phone_auto] }
Example 14
Source File: InitialActivity.java From cannonball-android with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FirebaseAuth auth = FirebaseAuth.getInstance(); if (auth.getCurrentUser() != null) { startThemeActivity(); } else { startLoginActivity(); } }
Example 15
Source File: RegisterPresenterImpl.java From Saude-no-Mapa with MIT License | 5 votes |
private void configureFirebaseAuth() { mFirebaseAuth = FirebaseAuth.getInstance(); mAuthListener = 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"); } }; }
Example 16
Source File: LoginActivity.java From Pharmacy-Android with GNU General Public License v3.0 | 5 votes |
private void firebaseLogin(String token) { final FirebaseDatabase ref = FirebaseDatabase.getInstance(); FirebaseAuth mAuth = FirebaseAuth.getInstance(); mAuth.signInWithCustomToken(token).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { firebaseLoginOrRegister(task.getResult().getUser()); } } }).addOnFailureListener(this, new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { showLoginError(); } }); /* ref.authWithCustomToken(token, new Firebase.AuthResultHandler() { @Override public void onAuthenticated(AuthData authData) { firebaseLoginOrRegister(authData); } @Override public void onAuthenticationError(FirebaseError firebaseError) { showLoginError(); } });*/ }
Example 17
Source File: LogInActivity.java From main with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_log_in); mAuth = FirebaseAuth.getInstance(); mUsername = findViewById(R.id.edit_login_username); mPassword = findViewById(R.id.edit_login_password); findViewById(R.id.button_login_login).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { loginHelper = new LogInHelper(mUsername.getText().toString(), mPassword.getText().toString()); if (loginHelper.getEmail().isEmpty()) { Toast.makeText(getApplicationContext(), "Enter email address", Toast.LENGTH_SHORT).show(); return; } if (loginHelper.getPassword().isEmpty()) { Toast.makeText(getApplicationContext(), "Enter password", Toast.LENGTH_SHORT).show(); return; } mAuth.signInWithEmailAndPassword(loginHelper.getEmail(), loginHelper.getPassword()) .addOnCompleteListener(LogInActivity.this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { Intent i = new Intent(LogInActivity.this, ViewProfileActivity.class); startActivity(i); finish(); } } }); } }); }
Example 18
Source File: ProfileFragment.java From Hify with MIT License | 4 votes |
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView= inflater.inflate(R.layout.frag_about_profile, container, false); mAuth = FirebaseAuth.getInstance(); mFirestore = FirebaseFirestore.getInstance(); profile_pic=rootView.findViewById(R.id.profile_pic); name=rootView.findViewById(R.id.name); username=rootView.findViewById(R.id.username); email=rootView.findViewById(R.id.email); location=rootView.findViewById(R.id.location); post=rootView.findViewById(R.id.posts); friend=rootView.findViewById(R.id.friends); bio=rootView.findViewById(R.id.bio); rootView.findViewById(R.id.frame).setVisibility(View.GONE); mFirestore.collection("Users") .document(mAuth.getCurrentUser().getUid()) .collection("Friends") .get() .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() { @Override public void onSuccess(QuerySnapshot documentSnapshots) { //Total Friends friend.setText(String.format(Locale.ENGLISH,"Total Friends : %d",documentSnapshots.size())); } }); userHelper = new UserHelper(rootView.getContext()); Cursor rs = userHelper.getData(1); rs.moveToFirst(); String usernam=rs.getString(rs.getColumnIndex(UserHelper.CONTACTS_COLUMN_USERNAME)); String nam = rs.getString(rs.getColumnIndex(UserHelper.CONTACTS_COLUMN_NAME)); String emai = rs.getString(rs.getColumnIndex(UserHelper.CONTACTS_COLUMN_EMAIL)); final String imag = rs.getString(rs.getColumnIndex(UserHelper.CONTACTS_COLUMN_IMAGE)); String loc=rs.getString(rs.getColumnIndex(UserHelper.CONTACTS_COLUMN_LOCATION)); String bi=rs.getString(rs.getColumnIndex(UserHelper.CONTACTS_COLUMN_BIO)); if (!rs.isClosed()) { rs.close(); } username.setText(String.format(Locale.ENGLISH,"@%s", usernam)); name.setText(nam); email.setText(emai); location.setText(loc); bio.setText(bi); Glide.with(rootView.getContext()) .setDefaultRequestOptions(new RequestOptions().placeholder(R.drawable.default_profile_picture)) .load(imag) .into(profile_pic); profile_pic.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { rootView.getContext().startActivity(new Intent(rootView.getContext(),ImagePreview.class) .putExtra("url",imag)); return false; } }); FirebaseFirestore.getInstance().collection("Posts") .whereEqualTo("userId",mAuth.getCurrentUser().getUid()) .get() .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() { @Override public void onSuccess(QuerySnapshot querySnapshot) { post.setText(String.format(Locale.ENGLISH,"Total Posts : %d",querySnapshot.size())); } }); return rootView; }
Example 19
Source File: LoginView.java From FastAccess with GNU General Public License v3.0 | 4 votes |
public FirebaseAuth getFirebaseAuth() { if (firebaseAuth == null) { firebaseAuth = FirebaseAuth.getInstance(); } return firebaseAuth; }
Example 20
Source File: FirebaseModule.java From triviums with MIT License | 4 votes |
@Singleton @Provides FirebaseAuth provideFirebaseAuth() { return FirebaseAuth.getInstance(); }