繁体   English   中英

Firebase云消息传递和Azure通知中心错误

[英]Firebase Cloud messaging and Azure Notification Hub Error

我有一个Xamarin for Visual Studio跨平台项目,并且在尝试使用Android项目中的Azure Notifications Hub来获取通知时遇到错误。 FirebaseInstanceIdService-derived类中,当我尝试实例化NotificationHub对象时收到错误。 这被称为在Azure Notifications Hub上注册用户/设备。

NotificationHub hub = new NotificationHub(Constants.NotificationHubName, Constants.ListenConnectionString, this);

我通常会收到此错误:

Unhandled Exception: Java.Lang.NullPointerException: occurred.

但也收到了:

Unhandled Exception: Java.Lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference occurred.

我是从DependencyService调用的,该服务在主页的OnAppearing事件中调用。 我不能依赖FirebaseInstanceIdService派生类中的OnTokenRefresh(),因为我需要用户首先登录。

我确认集线器名称和连接字符串正确。 而且上下文相关的错误肯定使它看起来与此相关。”但是我不确定问题是什么,因为这是我所看到的所有示例代码中如何处理的。

任何建议将不胜感激。

您是否在清单中插入了以下元素?

    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
    <intent-filter>
    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
    <category android:name="${applicationId}" />
    </intent-filter>
</receiver>

查看:

PS。 您可以发布其他代码吗? 识别问题可能很有用。

谢谢三ika 方法如下:

//AuthenticatedUser is a class in the mobile app.

public void RegisterWithNotificationServer(AuthenticatedUser savedUser)
        {
            string token = FirebaseInstanceId.Instance.Token;

            string customerNotificationTag = "customerid:" + savedUser.CustomerNotificationTagID;
            string userNotificationTag = "userid:" + savedUser.UserNotificationTagID;

        //Hub variable defined with class scope.            
            hub = new NotificationHub(Constants.NotificationHubName, Constants.ListenConnectionString, this);

            List<string> tags = new List<string>() { customerNotificationTag, userNotificationTag };
            Registration registration = hub.Register(token, tags.ToArray());
            string regID = registration.RegistrationId;

        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM