我正在尝试在Azure通知中心注册我的FCM服务。
我正在使用扩展FirebaseMessagingService()的实例ID服务获得有效的FCM令牌。
下面是我的InstanceIdService,它将返回有效令牌并启动我的registrationIntentService
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
这是我得到的例外:
Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
感谢任何帮助,因为我不知道正确配置所有内容后如何获得空指针异常。
答案 0 :(得分:0)
在初始化课堂上的String 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>";
}
您没有在字符串的开头添加"Endpoint=sb://"
(即public static String HubListenConnectionString ="Endpoint=sb://......"
。之后,您可能会遇到“找不到资源”异常错误。这就是我现在遇到的问题。< / p>