Fra*_*ank 3 ruby java android ruby-on-rails firebase-cloud-messaging
我正在尝试使用 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=>[]}
Run Code Online (Sandbox Code Playgroud)
但是在电话上我没有收到通知。
我的 ruby 后端如下所示:
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
Run Code Online (Sandbox Code Playgroud)
当应用程序打开时它会关闭,我发现这个错误:
java.lang.RuntimeException:无法实例化服务 NAME_OF_THE_APP.java.MyFirebaseMessagingService:java.lang.ClassNotFoundException:找不到类“NAME_OF_THE_APP.java.MyFirebaseMessagingService”
现在我不是 Java 专家所以我不知道现在有什么问题。我正在华为手机上测试。
已经发现我的错了。我遵循了有关 firebase 云消息传递的指南,在我的 Androidmanifest 中,文档说您需要通过以下内容:
<service
android:name=".java.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
但它给了我一个错误,它找不到类。经过一番搜索,如果发现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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
718 次 |
| 最近记录: |