【发布时间】:2020-11-09 04:49:59
【问题描述】:
我尝试从我的 android 项目调用 firebase 模拟器 中的函数。
我关注https://firebase.google.com/docs/functions/callable#java_2,但是当我调用 getHttpsCallable 时,我的 AVD 停止并且我在 logcat 或事件日志中看不到任何错误。
这里有一个比课程更短的代码,但也不起作用。
在 android Studio 中:(java)
public class MainActivity extends AppCompatActivity {
private final static String TAG = "DebugTest";
private DatabaseReference mRef ;
private FirebaseFunctions mFunctions;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button clickBtn = findViewById(R.id.clickBtn);
// WARNING: firebase emulators
mRef = FirebaseDatabase
.getInstance("http://10.0.2.2:9000?ns=nameOfMyApplication-xxxxx")
.getReference();
//crashe when I click on the button
clickBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mFunctions.getHttpsCallable("hello").call();
}
});
}
}
在 index.js 中
const functions = require('firebase-functions');
exports.hello = functions.https.onCall((data, context) => {
return `Hello world!`
})
该函数未在 firebase 模拟器套件的日志中调用。
【问题讨论】:
标签: android firebase-realtime-database google-cloud-functions avd