Calling a Cloud Function from Android through Firebase

前端 未结 4 1139
花落未央
花落未央 2020-12-25 14:53

Situation

I have created a Google Cloud Function through functions.https.onRequest, which is working nicely when I paste its URL in a browser and integ

4条回答
  •  旧时难觅i
    2020-12-25 15:25

    Since version 12.0.0 you can call cloud function in more simple way

    Add following line in your build.gradle

    implementation 'com.google.firebase:firebase-functions:19.0.2'
    

    And use following code

    FirebaseFunctions.getInstance() // Optional region: .getInstance("europe-west1")
        .getHttpsCallable("myCoolFunction")
        .call(optionalObject)
        .addOnFailureListener {
            Log.wtf("FF", it) 
        }
        .addOnSuccessListener {
            toast(it.data.toString())
        }
    

    You can use it on main thread safely. Callbacks is triggered on main thread as well.

    You can read more in official docs: https://firebase.google.com/docs/functions/callable

提交回复
热议问题