使用FirebaseInstallations和Firebasemesging代替FirebaseInstanceID

发布于 2025-02-06 22:50:11 字数 1887 浏览 2 评论 0 原文

我正在将我的项目集成到一个使用不推荐的接口 firebaseInstanceID 而不是 firebasemessaging firebaseInstallations 进行注册并接收输入呼叫的代码。

由于我是Firebase的新手,我不完全理解原始代码,因此我不确定如何更改它以实现所需的结果。

在查看这些帖子时,我无法完全提高理解并找到解决方案:

查看 firebase文档,我的基本理解是:

  1. firebaseInstanceId.getInstance() 我们正在返回类的实例
  2. .getInstanceId() 然后返回任务


  3. .addonsuccesslistener(this,instance -instance -> ...) 如果它是成功的

    fcmtoken = instanceIdresult.getToken() ,它会调用一个方法
  4. ,该方法获得了FCM Token

,但是我不确定如果这是正确的,我也不清楚此处的InstressIdresult和任务所代表的确切。

代码

/* Register your FCM token to receive incoming call invites */
private void registerForCallInvites() {
   FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(this, instanceIdResult -> {
            String fcmToken = instanceIdResult.getToken();
            Log.i(TAG, "Registering with FCM");
            Voice.register(accessToken, Voice.RegistrationChannel.FCM, fcmToken, registrationListener);
        });
}

此代码实际上是如何工作的,我该如何重写以使其编译?

I'm integrating to my project a piece of code that is using the deprecated interface FirebaseInstanceId instead of FirebaseMessaging and FirebaseInstallations to register and receive incoming calls.

As I am new to Firebase, I don't fully understand the original code and I'm unsure how to change it in order to achieve the desired outcome.

I wasn't able to fully improve my understanding and find a solution when looking at these posts:

Looking at the Firebase documentation, my basic understanding is that:

  1. FirebaseInstanceId.getInstance() we are returning an instance of the class
  2. .getInstanceId() to then returns a Task
  3. .addOnSuccessListener(this, instance -> ...) that then calls a method if it is succesful
  4. fcmToken = instanceIdResult.getToken() which gets a FCM Token

However, I'm not exactly sure if this is correct nor am I clear on what exactly the instanceIdResult and Task represent here.

Code

/* Register your FCM token to receive incoming call invites */
private void registerForCallInvites() {
   FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(this, instanceIdResult -> {
            String fcmToken = instanceIdResult.getToken();
            Log.i(TAG, "Registering with FCM");
            Voice.register(accessToken, Voice.RegistrationChannel.FCM, fcmToken, registrationListener);
        });
}

How does this code actually work and how would I go about rewriting it to make it compile?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

划一舟意中人 2025-02-13 22:50:11

转介到弃用的firebaseInstanceID,使用firebasemessaging:

FirebaseInstanceId.Instance.Token -> (string)FirebaseMessaging.Instance.GetToken()

请参阅此链接:

Referred to the deprecated FirebaseInstanceId, use FirebaseMessaging:

FirebaseInstanceId.Instance.Token -> (string)FirebaseMessaging.Instance.GetToken()

Please refer to this link:
https://gist.github.com/jfversluis/dd760594099066c7450d50cce6499368?permalink_comment_id=4485646#gistcomment-4485646

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文