通知は成功しましたが、Android携帯には表示されていません。Firebase通知がPHPを使用して表示されない
応答:
{"multicast_id":6696507350475373329,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1486651908616097%298b4204f9fd7ecd"}]}
PHP(SRC:https://gist.github.com/prime31/5675017)
<?php
// API access key from Google API's Console
define('API_ACCESS_KEY', ThisIsMyKey);
$registrationIds = array($_GET['id']);
// prep the bundle
$msg = array
(
'message' => 'TestNachricht',
'title' => 'TestTitel',
'subtitle' => 'TestSubTitle',
'vibrate' => 1,
'sound' => 1,
'priority' => 10,
'smallIcon' => 'small_icon'
);
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $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);
echo $result;
アンドロイド:
私はnotifcationsを放送するとの通知を送信することが可能ですので、私はonReceive-メソッドを追加しませんでしたFireBaseコンソールを使用して、特定のデバイス(RegistrationId)に接続します。それらのすべてが私のデバイスに表示されます。
private String getRegistrationId() {
return FirebaseInstanceId.getInstance().getToken();
}
<service android:name=".MyFirebaseInstanceIdService" android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
こんにちはデイブ。メッセージを受け取るためのAndroidサイドコードを追加することはできますか? –
私の投稿を編集しました。 – Dave