我已经在Android中集成了FCM。一切正常,但是当我的应用程序在后台时,它正在接收通知,但没有播放通知声音。
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notification_icon" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/notification_icon_background" />
我已经在应用程序标签内的Android.manifest中添加了上面的代码。
你能帮帮我吗?
我觉得以上所有答案都很有帮助,但是如果您需要从使用 java 开发的服务器端使用它,您需要这样做:
JSONArray registration_ids = new JSONArray(Arrays.asList(data));
message.put("registration_ids", registration_ids);
message.put("priority", "high");
JSONObject notification = new JSONObject();
notification.put("title", "Happy Googling");
notification.put("body", "A Sinha");
notification.put("sound","default");
message.put("notification", notification);
post.setEntity(new StringEntity(message.toString(), "UTF-8"));
请从您的服务器传递以下数据:
{
"to" : "deviceToken",
"notification" : {
"body" : "Pass body here",
"title" : "Title For Notification",
"icon" : " icon ",
"sound" : "notification sound here"
}
}
您也可以将声音部分作为"默认"传递
在有效负载中使用这样的字段。
$fields=array('to'=>fdfdfdfdsfdsdfdfdsfdsfdfdsfd" ,'notification'=>array('title'=>'mytitle','body'=>$title,'click_action'=>'abc','icon'=>'ic_stat_final','sound'=>'default','color'=>'#00aff0'),'data'=>array('ghmid'=>$hgmid,'page'=>$page));