Declare the dependency in app/build.gradle.
dependencies {
implementation platform('com.google.firebase:firebase-bom:30.1.0')
implementation 'com.google.firebase:firebase-functions'
}
private FirebaseFunctions mFunctions;
// ...
//In Activity
mFunctions = FirebaseFunctions.getInstance();
private Task<String> addMessage(String text) {
// Create the arguments to the callable function.
Map<String, Object> data = new HashMap<>();
data.put("text", text);
data.put("push", true);
return mFunctions
.getHttpsCallable("addMessage")
.call(data)
.continueWith(new Continuation<HttpsCallableResult, String>() {
@Override
public String then(@NonNull Task<HttpsCallableResult> task) throws Exception {
// This continuation runs on either success or failure, but if the task
// has failed then getResult() will throw an Exception which will be
// propagated down.
String result = (String) task.getResult().getData();
return result;
}
});
}
//Handle Error on client/user side
addMessage(inputMessage)
.addOnCompleteListener(new OnCompleteListener<String>() {
@Override
public void onComplete(@NonNull Task<String> task) {
if (!task.isSuccessful()) {
Exception e = task.getException();
if (e instanceof FirebaseFunctionsException) {
FirebaseFunctionsException ffe = (FirebaseFunctionsException) e;
FirebaseFunctionsException.Code code = ffe.getCode();
Object details = ffe.getDetails();
}
}
}
});
private FirebaseFunctions mFunctions;
// ...
mFunctions = FirebaseFunctions.getInstance();
private FirebaseFunctions mFunctions;
// ...
mFunctions = FirebaseFunctions.getInstance();
private FirebaseFunctions mFunctions;
// ...
mFunctions = FirebaseFunctions.getInstance();
Post a Comment