【问题标题】:How to send String from php firebase notification to notification service in android?如何将字符串从 php firebase 通知发送到 android 中的通知服务?
【发布时间】:2017-07-24 05:03:10
【问题描述】:

我想从 php.ini 发送一个带有 "room" 字符串的通知。这是我的代码:

define( 'API_ACCESS_KEY', '--------------------------' );
#prep the bundle
$msg = array (
    'body'  => $_GET['isi'],
    'title' => $nama." mengirim pesan",
    'icon'  => 'myicon',/*Default Icon*/
    'sound' => 'mySound',/*Default sound*/
    'room' => $room //This is String I want to send
);
$fields = array (
    'to'            => $registrationIds,
    'notification'  => $msg
);

$headers = array (
    'Authorization: key=' . API_ACCESS_KEY,
    'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec( $ch );
curl_close( $ch );

我想在这里收到一串“房间”:

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG = "MyFirebaseMessagingService";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        sendNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
    }
}

我怎样才能得到“房间”的字符串? 谢谢..

【问题讨论】:

    标签: php android firebase push-notification firebase-cloud-messaging


    【解决方案1】:

    notification 消息负载只有特定参数可供使用(请参阅here)。

    您将不得不使用data 消息负载来添加您的自定义键值对,然后相应地添加handle the messages

    【讨论】:

    • 谢谢.. 这很有帮助
    猜你喜欢
    • 2013-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-30
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多