2016-11-18 3 views
0

Я хочу, чтобы установить данные для отправки FirebaseFirebase локон добавить данные

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, чтобы получить значение «id_notification» из RemoteMessage, вам просто нужно прочитать его с карты.

@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

Нет работы! Ошибка приложения FATAL EXCEPTION: pool-4-thread-1 –

+0

no get value in android –

+0

Можете ли вы обновить вопрос, чтобы добавить именно код php, который вы используете, чтобы отправить сообщение и AndroidManifest и FirebaseMessagingService, которые вы расширили в своем приложении для Android? – BMacedo

Смежные вопросы