firebase connecten
Java
package com.example.phonechat;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
public class RegistrationActivity extends AppCompatActivity {
private Button mRegistration;
private EditText mEmail, mPassowrd, mName;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener firebaseAuthStateListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
firebaseAuthStateListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user!=null) {
Intent intent = new Intent(getApplication(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
return;
}
}
};
mAuth = FirebaseAuth.getInstance();
mRegistration = findViewById(R.id.registration);
mEmail = findViewById(R.id.gmail);
mName = findViewById(R.id.name);
mPassowrd = findViewById(R.id.password);
mRegistration.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String name = mName.getText().toString();
final String email = mEmail.getText().toString();
final String password = mPassowrd.getText().toString();
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(activity: getApplication(), new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(getApplicationContext(), "Sign in ERROR", Toast.LENGTH_SHORT).show();
}else{
String userId = mAuth.getCurrentUser().getUid();
DatabaseRefere currentUSerDb = FirebaseDatabase.getInstace().getRefernce().child("users").child(userId);
Map userinfo = new HashMap<>();
userInfo.put( k: "email", email);
userInfo.put( k: "name", name);
userInfo.put( k: "profileImageErl", v: "default");
currentUSerDb.updateChilderen(userInfo);
}
}
});
}
});
}
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(firebaseAuthStateListener);
}
@Override
protected void onStop() {
super.onStop();
mAuth.removeAuthStateListener(firebaseAuthStateListener);
}
}
Also in Java:
- Title
- java.lang.long cannot be cast to java.lang.integer
- Category
- Java
- Title
- java final meaning
- Category
- Java
- Title
- how to create a method java
- Category
- Java
- Title
- print values of bst java
- Category
- Java
- Title
- set view layout params android
- Category
- Java
- Title
- java 8 printstacktrace in system.out
- Category
- Java
- Title
- capcitor FERR_CLEARTEXT_NOT_PERMITTED
- Category
- Java
- Title
- gradle require java version
- Category
- Java
- Title
- how to add a number to an array in java
- Category
- Java
- Title
- for each java
- Category
- Java
- Title
- The shrinker may have failed to optimize the Java bytecode. To disable the shrinker, pass the `--no-shrink` flag to this command.
- Category
- Java
- Title
- how to find length of array in java
- Category
- Java
- Title
- using java 8 stream to process data in java
- Category
- Java
- Title
- convert string to byte java
- Category
- Java
- Title
- java connect to mysql
- Category
- Java
- Title
- java read from file
- Category
- Java
- Title
- random code
- Category
- Java
- Title
- teimpo en segundos java
- Category
- Java
- Title
- android studio centering textview in relativelayout
- Category
- Java
- Title
- how to create a subclass in java
- Category
- Java
- Title
- java get annotation value
- Category
- Java
- Title
- java script how to not allow soace
- Category
- Java
- Title
- java 8 stream option
- Category
- Java
- Title
- convert date to calendar java
- Category
- Java
- Title
- how to get the screen dimensions in java
- Category
- Java
- Title
- java best way to concatenate strings
- Category
- Java
- Title
- how to add multiple filter condition in Java stream filter chain
- Category
- Java
- Title
- system.out.println shortcut
- Category
- Java
- Title
- faire un timer en java
- Category
- Java
- Title
- Java system load from resources
- Category
- Java
- Title
- binary to int java
- Category
- Java
- Title
- cordova cannot find symbol import com.google.firebase.iid.FirebaseMessagingService;
- Category
- Java
- Title
- para que sirve getcontentpane en java
- Category
- Java
- Title
- import java.util.hashset
- Category
- Java
- Title
- count number of matches in two strings java
- Category
- Java
- Title
- wraping list to string java
- Category
- Java
- Title
- find maven version
- Category
- Java
- Title
- how to select a random element from an array in java
- Category
- Java
- Title
- take string from keyboard java
- Category
- Java
- Title
- java create window
- Category
- Java
- Title
- loop collection android
- Category
- Java
- Title
- hide elements android
- Category
- Java
- Title
- int to long java
- Category
- Java
- Title
- simple calculator program in java
- Category
- Java
- Title
- java convert a char[] to string
- Category
- Java
- Title
- java question mark operator
- Category
- Java
- Title
- how to exit a for loop in java
- Category
- Java
- Title
- hello world in java
- Category
- Java
- Title
- remove first character from string
- Category
- Java
- Title
- how to select a element in an arraylist java
- Category
- Java
- Title
- java.sql.SQLException: Before start of result set
- Category
- Java
- Title
- java scanner input int
- Category
- Java
- Title
- java random seed
- Category
- Java
- Title
- how to import jframe in java
- Category
- Java
- Title
- multiple string java
- Category
- Java
- Title
- java get folder content
- Category
- Java
- Title
- get drawable with string android java
- Category
- Java
- Title
- creating random color in java
- Category
- Java
- Title
- rewrite file java
- Category
- Java
- Title
- split with multiple condition in java
- Category
- Java
- Title
- enum in java
- Category
- Java
- Title
- java display message
- Category
- Java
- Title
- sieve in java
- Category
- Java
- Title
- java parse xml string
- Category
- Java
- Title
- regex get string between quotes java
- Category
- Java
- Title
- java repository sql find not in list
- Category
- Java
- Title
- how to set a windows background image tkinter
- Category
- Java
- Title
- how to create a linked list in java
- Category
- Java
- Title
- java arraylist to array
- Category
- Java
- Title
- switch statement in apex
- Category
- Java
- Title
- import classes from another project java
- Category
- Java
- Title
- mettre caractère de string en majuscule java
- Category
- Java
- Title
- gravity in java
- Category
- Java
- Title
- goodbye java
- Category
- Java
- Title
- vector in java
- Category
- Java
- Title
- find numbers in a string java
- Category
- Java
- Title
- init cap java
- Category
- Java
- Title
- declare bufferedreader java
- Category
- Java
- Title
- remove part of string java
- Category
- Java
- Title
- how to close a jframe in java with an if statement
- Category
- Java
- Title
- stackoverflow java enum with constructor
- Category
- Java
- Title
- spring framework iterate
- Category
- Java
- Title
- how to make int array java android
- Category
- Java
- Title
- compare string integer java
- Category
- Java
- Title
- java map string to list
- Category
- Java
- Title
- mutable string in java
- Category
- Java
- Title
- java function for power
- Category
- Java
- Title
- scan a string using scanner class in java
- Category
- Java
- Title
- java remove non numbers from string
- Category
- Java
- Title
- test function that call a function javascrip
- Category
- Java
- Title
- how to minimize jframe in java
- Category
- Java
- Title
- java loop through arraylist
- Category
- Java
- Title
- how to use beacon power in minecraft in java edition
- Category
- Java
- Title
- java - a program to print open ports
- Category
- Java
- Title
- validate request body java
- Category
- Java
- Title
- init admob
- Category
- Java
- Title
- java loop
- Category
- Java
- Title
- indexof java
- Category
- Java
- Title
- osmdroid offline map does not show
- Category
- Java
- Title
- hibernate onetone with mapsid
- Category
- Java