I try to upload my profile picture, also I get the message of the profile picture is been successfully upload but not able to see it in setting activity
I tried to change the firebase account but not able to work.
when I select photo it takes me to my internal storage, when I select the image it again takes me to choose section of photo uploading ways such as album, google photos internal storage, download etc. when the photo is been uploaded it is been showing in the firebase storage section but it is not showing in the app.
here is the code link
RootRef.child("Users").child(currentUserID)
.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
if ((dataSnapshot.exists()) && (dataSnapshot.hasChild("name") && (dataSnapshot.hasChild("image")))) {
String retrieveUserName = dataSnapshot.child("name").getValue().toString();
String retrieveUserStatus = dataSnapshot.child("status").getValue().toString();
String retrieveProfileImage = dataSnapshot.child("image").getValue().toString();
userName.setText(retrieveUserName);
userStatus.setText(retrieveUserStatus);
Picasso.get().load(retrieveProfileImage).into(userProfileImage);
}
else if ((dataSnapshot.exists()) && (dataSnapshot.hasChild("name"))) {
String retrieveUserName = dataSnapshot.child("name").getValue().toString();
String retrieveUserStatus = dataSnapshot.child("status").getValue().toString();
userName.setText(retrieveUserName);
userStatus.setText(retrieveUserStatus);
}
else {
userName.setVisibility(View.VISIBLE);
Toast.makeText(SettingsActivity.this, "Check The Details Again.", Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
private void UpdateSettings() {
String setUserName = userName.getText().toString();
String setStatus = userStatus.getText().toString();
if (TextUtils.isEmpty(setUserName)) {
Toast.makeText(this, "UserName is Empty.", Toast.LENGTH_SHORT).show();
}
if (TextUtils.isEmpty(setStatus)) {
Toast.makeText(this, "Status is Empty.", Toast.LENGTH_SHORT).show();
}
else {
HashMap<String, String> profileMap = new HashMap<>();
profileMap.put("uid", currentUserID);
profileMap.put("name", setUserName);
profileMap.put("status", setStatus);
RootRef.child("Users").child(currentUserID).setValue(profileMap)
.addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(Task<Void> task) {
if (task.isSuccessful()) {
SendUserToMainActivity();
Toast.makeText(SettingsActivity.this, "Profile Updates. Thank You!!!", Toast.LENGTH_SHORT).show();
}
else {
String message = task.getException().toString();
Toast.makeText(SettingsActivity.this, "Error: " + message, Toast.LENGTH_SHORT).show();
}
}
});
}
}```
I think you missed to send image from your app.
In UpdateSettings() method you have to send image to firebase.
In below HashMap add image and send to firebase,
HashMap<String, String> profileMap = new HashMap<>();
profileMap.put("uid", currentUserID);
profileMap.put("name", setUserName);
profileMap.put("status", setStatus);
profileMap.put("image", [YOUR_IMAGE_STRING]);
Related
have a problem, I'm working on a university project, I have two tables in firebase, the gallery table that contains the photos of the itinerary and the itinerary table that contains the various itineraries of the users now I have to make sure that the id of the itinerary and the ID of the image so as to have a photo corresponding to each itinerary ì, also created by the same user. I did so:
public void addImageItinerary() {
storageReference = FirebaseStorage.getInstance().getReference();
referenceDb = FirebaseDatabase.getInstance().getReference();
firestore = FirebaseFirestore.getInstance();
auth = FirebaseAuth.getInstance();
if (images != null) {
StorageReference itineraryRef = storageReference.child("itinerary_image/" + FirebaseAuth.getInstance().getCurrentUser().getUid() + ".jpg");
itineraryRef.putFile(images).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
#Override
public void onComplete(#NonNull Task<UploadTask.TaskSnapshot> task) {
if (task.isSuccessful()) {
itineraryRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
String itineraryId = referenceDb.child("Itinerary").push().getKey();
Log.i("itineraryId", itineraryId);
HashMap<String, Object> map = new HashMap<>();
map.put("image", uri.toString());
referenceDb.child("Gallery").child(FirebaseAuth.getInstance().getCurrentUser().getUid()+ "/" + itineraryId).setValue(map).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()) {
// APRO SCHERMATA MAPPA
// openMapFragment();
Toast.makeText(insertImage_fragment.getActivity(), "ok", Toast.LENGTH_SHORT).show();
} else {
//ERRORE
Toast.makeText(insertImage_fragment.getActivity(), "Operation failed. Please try again", Toast.LENGTH_SHORT).show();
}
}
});
}
});
} else {
Toast.makeText(insertImage_fragment.getActivity(), task.getException().toString(), Toast.LENGTH_SHORT).show();
}
}
});
} else{
Toast.makeText(insertImage_fragment.getActivity(),"Please add image", Toast.LENGTH_SHORT).show();
}
}
enter image description here
I'm trying to store details of user like name, email,age etc using Firebase in Android Studio, but it seems only the email and pasword is getting stored. Here's my code, where have I done mistakes? Only the real time database part of Firebase isn't somehow working here. Also, I couldn't post full code here because of "most of it is code add some more details" error.
regButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Email,Password etc are variables
final String Email= email.getText().toString().trim();
final String Password= password.getText().toString().trim();
final String FullName= fullName.getText().toString().trim();
final String Phone= phone.getText().toString().trim();
final String Gender= gender.getText().toString().trim();
final String Age= age.getText().toString().trim();
if (TextUtils.isEmpty(Email)){
email.setError("Email is required!");
return;
}
else{
loader.setMessage("Registration in process....");
loader.setCanceledOnTouchOutside(false);
loader.show();
mAuth.createUserWithEmailAndPassword(Email,Password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(!task.isSuccessful()){
String error =task.getException().toString();
Toast.makeText(SelectRegistrationActivity.this,
"Error occurred:" + error,Toast.LENGTH_SHORT).show();
}
else{
String currentUserId = mAuth.getCurrentUser().getUid();
userDatabaseRef= FirebaseDatabase.getInstance().getReference().child("Users").child(currentUserId);
HashMap userInfo=new HashMap();
userInfo.put("Name",fullName);
userInfo.put("Email",email);
userInfo.put("Age",age);
userInfo.put("Gender",gender);
userInfo.put("Phone",phone);
userInfo.put("Type","Patient");
userDatabaseRef.updateChildren(userInfo).addOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(#NonNull Task task) {
if (task.isSuccessful()){
Toast.makeText(SelectRegistrationActivity.this, "Details set Successful", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(SelectRegistrationActivity.this, task.getException().toString(), Toast.LENGTH_SHORT).show();
}
finish();
loader.dismiss();
}
});
}
}
});
I have a setup system to send name, email, profile pic, biography and username.
Then I did check if the username is taken into Firebase Firestore by QuerySnapshot (working) my problem is that when I change to an available username, the app enters into a loading loop and do nothing more. It doesn't send to the database or anything else.
I tried many times to solve this problem, but didn't find any solution yet. I moved the code, reorganized and nothing seens to solve.
The method is inside the onClick from a button.
Here's the code:
submitBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setup_progressbar.setVisibility(View.VISIBLE);
String name = setup_name.getText().toString();
String username = setup_username.getText().toString();
String userbio = setup_bio.getText().toString();
String email = setup_email.getText().toString();
if (!TextUtils.isEmpty(name) && mainImageURI != null) {
Query mQuery = db.collection("Users")
.whereEqualTo("username", username);
mQuery.addSnapshotListener(new EventListener<QuerySnapshot>() {
#Override
public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
for (DocumentSnapshot document: documentSnapshots){
if (document!=null){
duplicate = document.getString("username");
setup_username.setError("Ouch! This username is already taken. Please, try another.");
setup_progressbar.setVisibility(View.INVISIBLE);
} else {
if (isChanged) {
setup_progressbar.setVisibility(View.VISIBLE);
userid = firebaseAuth.getCurrentUser().getUid();
StorageReference imagePath = storageReference.child("profile_images").child(userid + ".jpg");
//StorageReference coverPath = storageReference.child("cover_images").child(userid + ".jpg");
imagePath.putFile(mainImageURI).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
imagePath.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
storeFireStore(uri, name, username, userbio, email);
FancyToast.makeText(getApplicationContext(), getString(R.string.enviando_foto), FancyToast.LENGTH_LONG, FancyToast.CONFUSING, R.drawable.ic_upload, false).show();
setup_progressbar.setVisibility(View.INVISIBLE);
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
String error = e.getMessage().toString();
FancyToast.makeText(getApplicationContext(), getString(R.string.fail_to_update_profile_pic) + error, FancyToast.LENGTH_LONG, FancyToast.ERROR, false).show();
setup_progressbar.setVisibility(View.INVISIBLE);
}
});
}
});
} else {
storeFireStore(null, name, username, userbio, email);
}
}
}
}
});
} else {
if (TextUtils.isEmpty(name)) {
setup_progressbar.setVisibility(View.INVISIBLE);
Snackbar snackbar = Snackbar.make(frameLayout, getString(R.string.empty_name), Snackbar.LENGTH_LONG);
snackbar.show();
} else if (TextUtils.isEmpty(username)) {
setup_progressbar.setVisibility(View.INVISIBLE);
Snackbar snackbar = Snackbar.make(frameLayout, getString(R.string.empty_username), Snackbar.LENGTH_LONG);
snackbar.show();
} else if (TextUtils.equals(username, duplicate)){
setup_username.setError("Ouch! This username is already taken. Please, try another.");
setup_progressbar.setVisibility(View.INVISIBLE);
} else if (TextUtils.isEmpty(email)) {
setup_progressbar.setVisibility(View.INVISIBLE);
Snackbar snackbar = Snackbar.make(frameLayout, getString(R.string.email_confirm), Snackbar.LENGTH_LONG);
snackbar.show();
} else {
setup_progressbar.setVisibility(View.INVISIBLE);
Snackbar snackbar = Snackbar.make(frameLayout, getString(R.string.pick_a_profile_pic), Snackbar.LENGTH_LONG);
snackbar.show();
}
}
}
private void storeFireStore(Uri uri, String name, String username, String userbio, String email) {
if (uri != null) {
downloadUrl = uri;
} else {
downloadUrl = mainImageURI;
//downloadUrl = mainCoverURI;
}
Map<String, String> userMap = new HashMap<>();
userMap.put("name", name);
userMap.put("username", username);
userMap.put("userbio", userbio);
userMap.put("email", email);
userMap.put("image", downloadUrl.toString());
//userMap.put("cover",downloadUrl.toString());
firebaseFirestore.collection("Users").document(userid).set(userMap).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()) {
FancyToast.makeText(getApplicationContext(), getString(R.string.profileUpdated), FancyToast.LENGTH_LONG, FancyToast.SUCCESS, false).show();
setup_progressbar.setVisibility(View.INVISIBLE);
finish();
} else {
String error = task.getException().getMessage();
FancyToast.makeText(getApplicationContext(), getString(R.string.fail_to_update_profile) + error, FancyToast.LENGTH_LONG, FancyToast.ERROR, false).show();
}
}
});
}
});
Here's a screenshot of the screen loop.
You likely don't need (or want) a "snapshot listener" for this use case. You likely just want to do a one-time fetch to see if the given user name exists.
You likely want to use a TRANSACTION in Firestore to first read if a matching document exists and if not to transaction.set() a new document. That way if others come in at the same time trying to create a doc with the same username, only one of the competing concurrent transactions will succeed.
Consider inserting the document to Firestore before you upload the item to Storage. It is the document is Firestore that is the potential "race-condition". Once you "own" the FS document, you can take your time to upload/update other data.
I am making an app about energy monitoring. In my sign up screen, there are four edit text (fullname, username, email, password) that will be send/ store to the firebase once the registration is successful. The data will be stored by the child username (something like this)
enter image description here
An esp32 is connected to firebase which will store a child under the username called totalEnergy (which is an int not string). (something like this)
enter image description here
in the log in screen there are 2 edit text (username, password)
What i would like to do is to set an error which is not letting the user login in the userdashboard if the totalEnergy is not yet stored by the esp32.
basically in order to go to userdashboard, the app need to fetch 5 child (username,fullname,email,password, totalEnergy). if totalEnergy is not yet given , i would like to set an error like "Your account is not yet ready! Please try again later".
Here is the sample code.
public void loginUser(View view) {
//validate login info
if (!validateUsername() | !validatePassword()) {
return;
} else {
progressBar.setVisibility(View.VISIBLE);
isUser();
}
}
private void isUser() {
final String userEnteredUsername = username.getEditText().getText().toString().trim();
final String userEnteredPassword = password.getEditText().getText().toString().trim();
rootNode = FirebaseDatabase.getInstance();
reference = rootNode.getReference("USER INFO");
Query checkUser = reference.orderByChild("username").equalTo(userEnteredUsername);
checkUser.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
if (snapshot.exists()) {
username.setError(null);
username.setErrorEnabled(false);
String passwordFromDB = snapshot.child(userEnteredUsername).child("password").getValue(String.class);
if (passwordFromDB.equals(userEnteredPassword)) {
username.setError(null);
username.setErrorEnabled(false);
String fullNameFromDB = snapshot.child(userEnteredUsername).child("fullName").getValue(String.class);
String usernameFromDB = snapshot.child(userEnteredUsername).child("username").getValue(String.class);
String emailFromDB = snapshot.child(userEnteredUsername).child("email").getValue(String.class);
Intent intent = new Intent(getApplicationContext(), UserDashboard.class);
Bundle extras = new Bundle();
int totalEnergyFromDB = snapshot.child(userEnteredUsername).child("totalEnergy").getValue(int.class);
intent.putExtra("fullName", fullNameFromDB);
intent.putExtra("username", usernameFromDB);
intent.putExtra("email", emailFromDB);
intent.putExtra("password", passwordFromDB);
extras.putString("totalEnergy", totalEnergyFromDB + "");
intent.putExtras(extras);
startActivity(intent);
} else {
progressBar.setVisibility(View.GONE);
password.setError("Wrong Password!");
password.requestFocus();
}
} else {
progressBar.setVisibility(View.GONE);
username.setError("No such user exist!");
username.requestFocus();
}
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
progressBar.setVisibility(View.GONE);
Toast.makeText(Login.this, error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
Im been doing this a week now, I cant figure it out! :( Please help !!! THANK YOU!
hello HB. this is the error :(
enter image description here
hello HB. app error :(
enter image description here
You can check if the esp32 is not -1 and only continue if it is not, like this:
if (passwordFromDB.equals(userEnteredPassword)) {
username.setError(null);
username.setErrorEnabled(false);
String fullNameFromDB = snapshot.child(userEnteredUsername).child("fullName").getValue(String.class);
String usernameFromDB = snapshot.child(userEnteredUsername).child("username").getValue(String.class);
String emailFromDB = snapshot.child(userEnteredUsername).child("email").getValue(String.class);
int totalEnergyFromDB = -1;
try {
totalEnergyFromDB = snapshot.child(userEnteredUsername).child("totalEnergy").getValue(int.class);
} catch (Exception e){
e.printStackTrace();
}
if (totalEnergyFromDB != -1) {
Intent intent = new Intent(getApplicationContext(), UserDashboard.class);
Bundle extras = new Bundle();
intent.putExtra("fullName", fullNameFromDB);
intent.putExtra("username", usernameFromDB);
intent.putExtra("email", emailFromDB);
intent.putExtra("password", passwordFromDB);
extras.putString("totalEnergy", totalEnergyFromDB + "");
intent.putExtras(extras);
startActivity(intent);
} else {
Toast.makeText(Login.this, "Your account is not yet ready! Please try again later", Toast.LENGTH_SHORT).show();
}
}
I'm trying to follow the tutorial from Firebase to allow users to login using their phone number. I've watched a tutorial video. All my code looks correct, but when I try it on my test device I receive a null pointer error.
at com.google.android.gms.common.internal.Preconditions.checkNotNull(Unknown Source)
at com.google.firebase.auth.PhoneAuthProvider.verifyPhoneNumber(Unknown Source)
at studios.p9p.chatomatic.chat_o_matic.PhoneLogin.CheckPhoneNumber(PhoneLogin.java:92)
at studios.p9p.chatomatic.chat_o_matic.PhoneLogin.access$000(PhoneLogin.java:29)
at studios.p9p.chatomatic.chat_o_matic.PhoneLogin$1.onClick(PhoneLogin.java:52)
My code for the phone login is as follows:
private EditText et_check_phone_number;
private EditText et_verify_code;
private Button btn_phone;
private Button btn_verify;
private String getPhoneNumber, getVerifactionCode;
private String mVerificationId = "";
private FirebaseAuth mAuth;
private FirebaseDatabase db;
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mcallBacks;
private PhoneAuthProvider.ForceResendingToken mResendToken;
private ProgressDialog mloading;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_phone_login);
mAuth = FirebaseAuth.getInstance();
initVariables();
btn_phone.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
CheckPhoneNumber();
}
});
btn_verify.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
VerifyPhoneNumber();
}
});
}
private void initVariables() {
et_check_phone_number = findViewById(R.id.et_phonenumber);
et_verify_code = findViewById(R.id.etvarifaction);
btn_phone = findViewById(R.id.btn_phone_login);
btn_verify = findViewById(R.id.btn_phone_verify);
mloading = new ProgressDialog(this);
}
private void CheckPhoneNumber() {
getPhoneNumber = et_check_phone_number.getText().toString();
if (TextUtils.isEmpty(getPhoneNumber))
{
Toast.makeText(this, "Phone Number Field Cant Be Empty...", Toast.LENGTH_SHORT).show();
} else{
mloading.setTitle("Checking Your Phone Number");
mloading.setMessage("It Gonna Take A Second...");
mloading.setCanceledOnTouchOutside(false);
mloading.setIcon(R.mipmap.ic_launcher);
mloading.show();
PhoneAuthProvider.getInstance().verifyPhoneNumber(
getPhoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mcallBacks);
}
}
mcallBacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
#Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
signInWithPhoneAuthCredential(phoneAuthCredential);
}
#Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(PhoneLogin.this, "Wrong Or Invalid Phone Number...", Toast.LENGTH_SHORT).show();
btn_phone.setVisibility(View.VISIBLE);
et_check_phone_number.setVisibility(View.VISIBLE);
et_verify_code.setVisibility(View.INVISIBLE);
btn_verify.setVisibility(View.INVISIBLE);
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(getBaseContext(), "Invalid Request " + e.toString(), Toast.LENGTH_SHORT).show();
} else if (e instanceof FirebaseTooManyRequestsException) {
Toast.makeText(getBaseContext(), "The SMS quota for the project has been exceeded " + e.toString(), Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
// Save verification ID and resending token so we can use them later
mVerificationId = verificationId;
mResendToken = token;
Toast.makeText(PhoneLogin.this, "Code Sent Please Check Your SMS...", Toast.LENGTH_SHORT).show();
btn_phone.setVisibility(View.INVISIBLE);
et_check_phone_number.setVisibility(View.INVISIBLE);
et_verify_code.setVisibility(View.VISIBLE);
btn_verify.setVisibility(View.VISIBLE);
}
};
}
private void VerifyPhoneNumber() {
getVerifactionCode = et_verify_code.getText().toString();
if (TextUtils.isEmpty(getVerifactionCode)){
Toast.makeText(this, "Please Enter The Code Sent To Your SMS...", Toast.LENGTH_SHORT).show();
}else{
mloading.setTitle("Checking Your Verification code ");
mloading.setMessage("Ill Be Back In A Jiffy...");
mloading.setCanceledOnTouchOutside(false);
mloading.setIcon(R.mipmap.ic_launcher);
mloading.show();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, getVerifactionCode);
signInWithPhoneAuthCredential(credential);
}
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
mloading.dismiss();
Toast.makeText(PhoneLogin.this, "Login Successful...", Toast.LENGTH_SHORT).show();
Intent phoneloginIntent =new Intent (getBaseContext(),Home_Screen.class);
phoneloginIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(phoneloginIntent);
finish();
} else {
String mesage = task.getException().toString();
Toast.makeText(PhoneLogin.this, "Error: " + mesage, Toast.LENGTH_SHORT).show();
}
}
});
}
The "+44" I added trying to see if I was entering the wrong phone number. I tried it by adding the +44 manually into the edit text of the app first and that gave the same error.
Edit
So I've removed the line inside the Auth provider that asked if the number was larger than 9 digits as it wasn't working. Also I ran a log to see if it capturing the phone number correctly.
Log.i("Verify_Phone_Number",getPhoneNumber);
2019-07-16 14:15:30.585 32055-32055/studios.p9p.chatomatic.chat_o_matic I/Verify_Phone_Number: +447******100 and it returns correctly
Edit 2
So on further testing if I click btn_phone before entering the phone number it works correctly, but if I simply add the phone number to the edit test first then press thebtn_phone it crashes with the above message in logcat.
As per Firebase Docs you have to pass the Number with Country Code :
E.g.
phone number = +919090909090
See Following Picture :
As you can see even testing number needs country code with them.
When your app crashes it means Firebase PhoneAuthProvider.getInstance().verifyPhoneNumber() not getting the number with country code.
You can try this following code before passing to if condition :
if (et_check_phone_number.getText().toString().startsWith("+44"){
getPhoneNumber = et_check_phone_number.getText().toString();
}else{
getPhoneNumber = "+44"+et_check_phone_number.getText().toString();
}
Above Code will check whether user put prefix of your country code or not.
Ok so the way i solved this problem was to move the mcallbacks to the on create section of code. as shown below
setContentView(R.layout.activity_phone__login);
mAuth = FirebaseAuth.getInstance();
InitVariables();
AddPhoneNumberButtons();
mcallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
#Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
signInWithPhoneAuthCredential(phoneAuthCredential);
}
#Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(getBaseContext(), "Wrong Or Invalid Phone Number...", Toast.LENGTH_SHORT).show();
AddPhoneNumberButtons();
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(getBaseContext(), "Invalid Request " + e.toString(), Toast.LENGTH_SHORT).show();
} else if (e instanceof FirebaseTooManyRequestsException) {
Toast.makeText(getBaseContext(), "The SMS quota for the project has been exceeded " + e.toString(), Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
// Save verification ID and resending token so we can use them later
verificationid = verificationId;
mresendtoken = token;
Toast.makeText(getBaseContext(), "Code Sent Please Check Your SMS...", Toast.LENGTH_SHORT).show();
AddVerifyButtons();
}
};