Firebase函数可生成android应用程序
我试图在android应用程序中显示firebase函数的结果。 这是我练习的第一个函数。我正确地部署了我的函数,,并且在控制台中运行良好。然后我想做的下一步是:如何在Android的空活动中显示我的函数结果??或者功能和android应用程序之间的连接步骤是什么 这是我的简单功能:Firebase函数可生成android应用程序,android,firebase,google-cloud-functions,Android,Firebase,Google Cloud Functions,我试图在android应用程序中显示firebase函数的结果。 这是我练习的第一个函数。我正确地部署了我的函数,,并且在控制台中运行良好。然后我想做的下一步是:如何在Android的空活动中显示我的函数结果??或者功能和android应用程序之间的连接步骤是什么 这是我的简单功能: const functions = require('firebase-functions'); // Create and Deploy Your First Cloud Functions // https
const functions = require('firebase-functions');
// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
要从android应用程序与firebase http云函数通信,您需要使用任何http客户端库,如OkHttp 您可以从firebase控制台获取云函数的URL
OkHttpClient httpClient = new OkHttpClient();
HttpUrl.Builder httpBuider =
HttpUrl.parse(FIREBASE_CLOUD_FUNCTION_URL).newBuilder();
Request request = new Request.Builder().
url(httpBuider.build()).build();
httpClient.newCall(request).enqueue(new Callback() {
@Override public void onFailure(Call call, IOException e) {
Log.e(TAG, "error in getting response from firebase cloud function");
}
@Override public void onResponse(Call call, Response response){
ResponseBody responseBody = response.body();
String resp = "";
if (!response.isSuccessful()) {
Log.e(TAG, "fail response from firebase cloud function");
}else {
Log.e(TAG, "respone "+resp);
}
}
});
}
有关完整示例,请参见您可能应该在应用程序中使用HTTPS可调用函数。