我正在尝试使用FCM GEM向Android手机发送推送通知消息。我能够获得设备令牌,我认为我应该按照应有的方式进行设置。只有当我使用Ruby后端发送测试消息时,才会得到以下响应:
{:body=>"{"multicast_id":7171621681139926581,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1556626239337337%e087ffcde087ffcd"}]}", :headers=>{"content-type"=>["application/json; charset=UTF-8"], "date"=>["Tue, 30 Apr 2019 12:10:39 GMT"], "expires"=>["Tue, 30 Apr 2019 12:10:39 GMT"], "cache-control"=>["private, max-age=0"], "x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"], "x-xss-protection"=>["1; mode=block"], "server"=>["GSE"], "alt-svc"=>["quic=":443"; ma=2592000; v="46,44,43,39""], "accept-ranges"=>["none"], "vary"=>["Accept-Encoding"], "connection"=>["close"]}, :status_code=>200, :response=>"success", :canonical_ids=>[], :not_registered_ids=>[]}
但是在电话上,我没有收到通知。
我的红宝石后端看起来像这样:
fcm_client = FCM.new(server_key)
# options = {:notification => "Test notification",:data => {:message => "This is a FCM Topic Message!"}}
options = { "notification": {
"title": "Portugal vs. Denmark",
"body": "5 to 1"
}
}
user_device_ids.each_slice(20) do |device_ids|
response = fcm_client.send_notification(device_ids, options)
p response
end
当应用打开时,它会关闭,我发现此错误:
java.lang.runtimeException:无法实例化服务 name_of_the_app.java.myfirebasemessagingservice: java.lang.classnotfoundexception:找不到类 " name_of_the_app.java.myfirebasemessagingservice"
现在我不是Java专家,所以我不知道这一点是什么问题。我正在通过华为手机进行测试。
已经找到了我的错。我遵循了Firebase Cloud Messaging的指南,在矿山中,文档说您需要通过以下方式:
<service
android:name=".java.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
,但它给我一个无法找到该类的错误。稍作搜索后,如果发现Android名称是错误的:
应该是:
<service
android:name="com.google.firebase.messaging.FirebaseMessagingService">
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>