Remote Config doesnt fetch anything - android

I'm having an issue with Firebase's remote config, the same code works just fine in another app, but on this app i'm working on i'm barely works!! i've checked "connect your app to firebase" and "add remote config to your app" everything is OK, so i think the problem is somehow with the code, because i don't see any "fetch succeded" or "fetch failed" in logs:
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
mRemoteConfig.fetch(0)
.addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(Task<Void> task) {
if (task.isSuccessful()) {
Log.d("firebaseconfig", "Fetch Succeeded");
// Once the config is successfully fetched it must be activated before newly fetched
// values are returned.
mRemoteConfig.activateFetched();
} else {
Log.d("firebaseconfig", "Fetch failed");
}
}
});
}
}, 0);
Any help pleeease? Thank you very much

Related

addOnFailureListener not working in offline mode and network issues

addOnFailureListner does not work for add() data, but addOnFailureListner works for get().
This is not working
WorkPlaceRef.add(DATA).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
#Override
public void onComplete(#NonNull Task<DocumentReference> task) {
//Successfully created - This one triggers when I turn on wifi again.
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
// Error - This addonFailureListner is not working when there are no network.
}
});
This is working
WorkPlaceRef.get().addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
#Override
public void onComplete(#NonNull Task<DocumentReference> task) {
//Successfully received - This one triggers when I turn on wifi again.
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
// Error - this addonFialureListner triggers when there is no network.
}
});
It's not a failure to attempt to write data while offline. The Firestore SDK will write the data in a local offline cache first, and eventually synchronize that write with the server when the app comes back online. The success listener will be invoked whenever that happens.
Write failures only happen when there is some problem that can't be retried due to lack of connectivity, such as security rule violations, or exceeding some documented limit of the database.
If you want to know if some document data is not yet synchronized with the server, you can check its metadata to know if a write is pending.

Firebase authentication sign in problem in java

I wrote a login system using Firebase. What I want to do now :
If the user has trouble registering (for example, if he tries to log in with an already registered e-mail), I want to print the error in the warning message and redirect it to the sign-up page.
For this, I have written a code such as below, into register button.
// Sign Up Method
// Kullanıcı Kayıt etme metodu
public void signUp(View view) {
mAuth.createUserWithEmailAndPassword(emailText.getText().toString(),passwordText.getText().toString())
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
Toast.makeText(signupPage.this, "User Created", Toast.LENGTH_SHORT).show();
Intent homePage = new Intent(signupPage.this, ProfilePage.class);
startActivity(homePage);
finish();
}
}).addOnFailureListener(this, new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
}
}).addOnFailureListener(this, new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
if (mAuth.getCurrentUser() != null) {
Intent signBack = new Intent(signupPage.this, signupPage.class);
startActivity(signBack);
finish();
}
Toast.makeText(signupPage.this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}
});
If there is a problem when User logging in, doing show error message. But it does not redirect to the registration page. Although it shows an error, the user redirects it to the home page as if it were registered successfully.
I would appreciate it if you could help me with this.
Sorry for my bad English.
Well, first you must to know that the onComplete method will be called always, since onFailure only when something fails. So, as I see on your code the app will always launch home.
How to solve?
Just check if the task is successful for redirect to homepage.
In the onComplete method check if all is ok and execute your code with: if (task.isSuccessful)...

Why does PlacesClient.fetchPlace Task never hit a callback

I'm migrating from the old Android Places API to either the new one or the compatibility library, in both approaches the auto prediction search works, but getting more details from the ID of the selected location appears to never complete.
I started with the compatibility library, the initial autoPrediction lookup works as expected. Suggesting the API key and account are fine. But getPlaceByID failed to finish.
I've switched to the new API instead, again, the new FindAutocompletePredictions works, but the fetchPlaces task never finishes.
I've boiled the code down to manually putting an ID in, only asking for LatLong, and having all the available listeners with breakpoints. They are never hit.
List<Place.Field> placeFields = Arrays.asList(Place.Field.LAT_LNG);
FetchPlaceRequest request = FetchPlaceRequest.builder("EhtHbGFzZ293IFN0cmVldCwgR2xhc2dvdywgVUsiLiosChQKEgmvXKElzUWISBFN3LArF1aEERIUChIJqZHHQhE7WgIReiWIMkOg-MQ", placeFields)
.build();
placesClient.fetchPlace(request).addOnCompleteListener(new OnCompleteListener<FetchPlaceResponse>() {
#Override
public void onComplete(#NonNull Task<FetchPlaceResponse> task) {
System.out.println("");
}
}).addOnCanceledListener(new OnCanceledListener() {
#Override
public void onCanceled() {
System.out.println("");
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
System.out.println("");
}
}).addOnSuccessListener(new OnSuccessListener<FetchPlaceResponse>() {
#Override
public void onSuccess(FetchPlaceResponse fetchPlaceResponse) {
System.out.println("");
}
});
I would expect to hit one of the listeners and see a place, or some reason for it to fail. Or, at least something in the logcat to say what's going on.
Use
public Task<TResult> addOnCompleteListener(#NonNull OnCompleteListener<TResult> var1)

mFirebaseRemoteConfig.fetch() doesn't return

mFirebaseRemoteConfig.fetch(0)
.addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()) {
System.out.println("Fetch Succeeded");
// Once the config is successfully fetched it must be
// values are returned.
mFirebaseRemoteConfig.activateFetched();
} else {
System.out.println("Fetch failed");
}
}
});
I added this to get the remote config from the server. I was able to get the values a couple of times. I updated the remote config conditions after that and now fetch doesnt return anything. Tried a lot of approaches including moving the call after on onResume and calling it from a separate thread. Updating to 9.2.1 also didnt worked for me
What else can be done to get the config?

How do you retrieve the error code from a Firebase Task<AuthResult> unsuccessful login?

I am currently wondering how it is possible to gain the error code after carrying out an unsuccessful login using Firebase. From their legacy code, that you can see in this link below:
https://www.firebase.com/docs/android/guide/user-auth.html#section-handling-errors
#Override
public void onAuthenticationError(FirebaseError error) {
switch (error.getCode()) {
case FirebaseError.USER_DOES_NOT_EXIST:
// handle a non existing user
break;
case FirebaseError.INVALID_PASSWORD:
// handle an invalid password
break;
default:
// handle other errors
break;
}
}
You are provided an onAuthenticationError, where the FirebaseError can then be specifically analysed to produce a different feedback error to the user. However as they have recently released their new API, I have started to work with that. Here is the code I have to utilise now:
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
//If authentication fails
if (!task.isSuccessful()) {
// Handle the specific individual errors such as incorrect passwords
}
}
Unfortunately I am not sure how I am able to gather the specific error code from the Task<AuthResult> object. I understand that I can gather the Exception and Toast this message, although I would prefer to carry out a switch on a proper error code rather than work with a String explaining the error that occurred.
If your code already has onCompleteListener then I won't recommend you to add onFailureListner just get information about the exception because it will increase the number of listeners.
You can get an error code and message as follow.
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
//If authentication fails
if (!task.isSuccessful()) {
String message = task.getException().getMessage();
String localizedMessage = task.getException().getLocalizedMessage();
String errorCode = ((FirebaseAuthInvalidUserException) task.getException()).getErrorCode();
}
}
I will recommend using Localized Message instead of just Message because a Localized message is short and has enough the information necessary to tackle the error.
you have to add the onFailureListner()
with the code below you can get the error code :
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
if (e instanceof FirebaseAuthInvalidCredentialsException) {
notifyUser("Invalid password");
} else if (e instanceof FirebaseAuthInvalidUserException) {
String errorCode =
((FirebaseAuthInvalidUserException) e).getErrorCode();
if (errorCode.equals("ERROR_USER_NOT_FOUND")) {
notifyUser("No matching account found");
} else if (errorCode.equals("ERROR_USER_DISABLED")) {
notifyUser("User account has been disabled");
} else {
notifyUser(e.getLocalizedMessage());
}
}
}
});
notifyUser() method you should develop to show Toast or snackbar or dialog maybe
I'd struggled with this a bit, but found the answer. give it a try:
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(activity, "Authentication completed.",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(activity, "Authentication failed:" +
task.getException(), Toast.LENGTH_SHORT).show();
}
to get the exception i'd used: task.getException().
good luck
Better to use
task.getException().getMessage()
to get well formated message for user

Categories

Resources