add firebase angular
npm install firebase @angular/fire
add firebase angular
npm install firebase @angular/fire
how to connect with firebase in android studio manually
FIRE BASE AUTOMATICALLY SETUP
1. ANDROID STUDIO -> TOOLS -> FIRE BASE
2. FIRE BASE ASSISTANT OPEN
3. FROM ASSISTANT GO TO ANY FIRE BASE PRODUCT AND OPEN IT
4. CLICK CONNECT TO FIREBASE
5. CLICK ADD DEPENDENCIES
how to connect with firebase in android studio manually
FIRE BASE MANUALL SETUP
1. GO TO FIREBASE CONSOLE
2. CREATE NEW PROJECT
3. ADD ANDROID PACAKAGE NAME
4. ADD SHA-1
5. ADD NICKNAME
6. DOWNLOAD JSON FILE ADD COPY/PASTE TO YOUR PROJECT
7. DOWNLOAD DEPENDENCIES
firebase connecten
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);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us