2016-11-18 80 views
0

我想設置數據發送火力地堡火力地堡捲曲添加數據

function sendFCM($body,$id,$title,$url) { 
    $url = 'https://fcm.googleapis.com/fcm/send'; 
    $fields = array (
      'to' => $id, 
      'notification' => array (
        "body" => $body, 
        "title" => $title, 
        "icon" => $url, 
AND HERE???? HOW SET DATA? 
      'data' => array (
      "id_notification" => $id_notification 
    ) 
    ) 
    ); 
    $fields = json_encode ($fields); 
    $headers = array (
      'Authorization: key=' . "", 
      'Content-Type: application/json' 
    ); 

    $ch = curl_init(); 
    curl_setopt ($ch, CURLOPT_URL, $url); 
    curl_setopt ($ch, CURLOPT_POST, true); 
    curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $fields); 

    $result = curl_exec ($ch); 
    curl_close ($ch); 
    } 

我更新代碼:::::::

Firebasemessaging

public class MyFirebaseMessagingService extends FirebaseMessagingService { 
    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 

     UrI alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     if(alarmSound == null){ 
      alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     } 

     String Body = remoteMessage.getNotification().getBody(); 
     String Titolo = remoteMessage.getNotification().getTitle(); 
     String Icona = remoteMessage.getNotification().getIcon(); 
     String TAG = remoteMessage.getNotification().getTag(); 
     String Colore = remoteMessage.getNotification().getColor(); 

     sendNotification(Body,Titolo,Icona,TAG,Colore); 
    } 

而在Android的中MessageReceiver()如何獲取數據?例如,我想獲得id_notification

謝謝大家的幫助!

+0

你是什麼意思'id_notification' – Selvin

+0

識別器的通知 –

+0

一個你還不發送或'NotificationManager.notify'的一個(也不叫)......嗯,也許時間旅行將在未來訪問... – Selvin

回答

0

根據Firebase documentation爲了從RemoteMessage獲得「id_notification」值,你只需要從Map中讀取它。

@Override 
public void onMessageReceived(RemoteMessage remoteMessage) { 
    // ... 

    // Check if message contains a data payload. 
    if (remoteMessage.getData().size() > 0) { 
     String idNotification = remoteMessage.getData().get("id_notification"); 
    } 

} 
+0

沒有工作!應用程序崩潰致命異常:pool-4-thread-1 –

+0

在android中無法獲取值 –

+0

您是否可以更新問題以完全添加用於發送消息的PHP代碼以及在Android應用中擴展的AndroidManifest和FirebaseMessagingService? – BMacedo