带有FCM的Azure通知中心-NullPointerException
我正在尝试向Azure通知中心注册我的FCM服务带有FCM的Azure通知中心-NullPointerException,azure,notifications,push,Azure,Notifications,Push,我正在尝试向Azure通知中心注册我的FCM服务 // Declare the azure notification hub val notificationHub = NotificationHub( // Provide our notification hub name CentreMK.FCM_NOTIFICATION_HUB_NAME, // Provide our notification hub connection string
// Declare the azure notification hub
val notificationHub = NotificationHub(
// Provide our notification hub name
CentreMK.FCM_NOTIFICATION_HUB_NAME,
// Provide our notification hub connection string
CentreMK.FCM_NOTIFICATION_HUB_LISTEN_CONNECTION_STRING,
// The context of this service
this)
// Log the event
Log.i(TAG, "Attempting to register with NH using token : $token")
// Update the registration id by registering our token with the notification hub
// This provides us with the registration id
regID = notificationHub.register(token).registrationId
我正在使用扩展FirebaseMessagingService()的实例Id服务获取有效的FCM令牌
下面是我的InstancedService,它返回一个有效令牌并启动我的RegistrationInstantService
class FCMInstanceIdService : FirebaseMessagingService() {
companion object {
private const val TAG = "FCMInstanceIDService"
}
init {
Log.i(TAG, "init")
}
override fun onNewToken(refreshedToken: String?) {
FirebaseInstanceId.getInstance().instanceId.addOnSuccessListener { instanceIdResult ->
instanceIdResult.token
// Log the event
Log.i(TAG, "Refreshing GCM Registration Token")
// Declare our intent to start the service
val intent = Intent(this, FCMRegistrationIntentService::class.java)
// Start the service!
startService(intent)
}
}
}
下面是我尝试在通知中心注册此令牌的代码部分
// Declare the azure notification hub
val notificationHub = NotificationHub(
// Provide our notification hub name
CentreMK.FCM_NOTIFICATION_HUB_NAME,
// Provide our notification hub connection string
CentreMK.FCM_NOTIFICATION_HUB_LISTEN_CONNECTION_STRING,
// The context of this service
this)
// Log the event
Log.i(TAG, "Attempting to register with NH using token : $token")
// Update the registration id by registering our token with the notification hub
// This provides us with the registration id
regID = notificationHub.register(token).registrationId
这是我得到的例外:
非常感谢您的帮助,因为我不知道在正确配置所有内容后,如何可能出现空指针异常。在初始化类中的
字符串HubListenConnectionString
时:
public class NotificationSettings {
public static String SenderId = "<Your project number>";
public static String HubName = "<Your HubName>";
public static String HubListenConnectionString = "<Enter your DefaultListenSharedAccessSignature connection string>";
}
公共类通知设置{
公共静态字符串SenderId=“”;
公共静态字符串HubName=“”;
公共静态字符串HubListenConnectionString=“”;
}
您没有将“Endpoint=sb://”
添加到字符串的开头(即:公共静态字符串HubListenConnectionString=“Endpoint=sb://”
。在此之后,您可能会遇到“Resource not found”(未找到资源)异常错误。这就是我现在遇到的问题