Firebase Cloud Messaging には、メッセージを複数のデバイスに向ける 2 つの方法があります。
- トピック メッセージング。特定のトピックにオプトインしている複数のデバイスにメッセージを送信できます。
- デバイス グループ メッセージング。定義したグループに属する複数のデバイスにメッセージを送信できます。
このチュートリアルでは、FCM 用のAdmin SDKまたはREST APIを使用してアプリ サーバーからトピック メッセージを送信し、Android アプリでそれらを受信して処理することに焦点を当てています。バックグラウンド アプリとフォアグラウンド アプリの両方のメッセージ処理について説明します。セットアップから検証まで、これを達成するためのすべてのステップがカバーされています。
SDK をセットアップする
このセクションでは、FCM用の Android クライアント アプリをセットアップした場合、または最初のメッセージを送信する手順を実行した場合に、既に完了している手順について説明する場合があります。
あなたが始める前に
Android Studioを最新バージョンにインストールまたは更新します。
プロジェクトが次の要件を満たしていることを確認してください。
- API レベル 19 (KitKat) 以上を対象としています
- Android 4.4 以降を使用
- 次のバージョン要件を満たすことを含むJetpack (AndroidX)を使用します。
-
com.android.tools.build:gradle
v3.2.1 以降 compileSdkVersion
28以降
-
物理デバイスをセットアップするか、エミュレーターを使用してアプリを実行します。
Google Play サービスに依存する Firebase SDK では、デバイスまたはエミュレータに Google Play サービスがインストールされている必要があることに注意してください。Google アカウントを使用して Firebase にサインインします。
Android プロジェクトをまだ持っておらず、Firebase 製品を試してみたいだけの場合は、クイックスタート サンプルのいずれかをダウンロードできます。
Firebase プロジェクトを作成する
Firebase を Android アプリに追加する前に、Firebase プロジェクトを作成して Android アプリに接続する必要があります。 Firebase プロジェクトについて詳しくは、 Firebase プロジェクトを理解するをご覧ください。
アプリを Firebase に登録する
Android アプリで Firebase を使用するには、アプリを Firebase プロジェクトに登録する必要があります。アプリを登録することは、多くの場合、アプリをプロジェクトに「追加する」と呼ばれます。
Firebase コンソールに移動します。
プロジェクトの概要ページの中央にあるAndroidアイコン (
) または [アプリの追加] をクリックして、セットアップ ワークフローを起動します。[ Android パッケージ名] フィールドにアプリのパッケージ名を入力します。
パッケージ名は、デバイスと Google Play ストアでアプリを一意に識別します。
パッケージ名は、アプリケーション IDと呼ばれることがよくあります。
モジュール (アプリ レベル) の Gradle ファイルでアプリのパッケージ名を見つけます。通常は
app/build.gradle
(パッケージ名の例:com.yourcompany.yourproject
) です。パッケージ名の値は大文字と小文字が区別されることに注意してください。この Firebase Android アプリを Firebase プロジェクトに登録した後は、この値を変更することはできません。
(オプション)その他のアプリ情報を入力します:アプリのニックネームとデバッグ署名証明書 SHA-1 。
アプリのニックネーム: Firebase コンソールでのみ表示される、内部の便利な識別子
デバッグ署名証明書 SHA-1 : SHA-1 ハッシュは、Firebase Authentication ( Google サインインまたは電話番号サインインを使用する場合) とFirebase Dynamic Linksで必要です。
[アプリを登録]をクリックします。
Firebase 構成ファイルを追加する
Firebase Android 構成ファイル (
) をダウンロードしてアプリに追加します。google-services.json [ google-services.json をダウンロード] をクリックして、Firebase Android 構成ファイルを取得します。
構成ファイルをアプリのモジュール (アプリ レベル)ルート ディレクトリに移動します。
Firebase 構成ファイルには、プロジェクトの一意であるが秘密ではない識別子が含まれています。この構成ファイルの詳細については、 Firebase プロジェクトを理解するをご覧ください。
Firebase 構成ファイルはいつでも再ダウンロードできます。
構成ファイル名に
(2)
のような追加の文字が追加されていないことを確認してください。
構成ファイルの値に Firebase SDK がアクセスできるようにするには、 Google サービス Gradle プラグイン(google-services.json google-services
) が必要です。ルート レベル (プロジェクト レベル) のGradle ファイル (
<project>/build.gradle
) で、Google サービス プラグインをビルドスクリプトの依存関係として追加します。buildscript { repositories { // Make sure that you have the following two repositories google() // Google's Maven repository mavenCentral() // Maven Central repository } dependencies { ... // Add the dependency for the Google services Gradle plugin classpath 'com.google.gms:google-services:4.3.15' } } allprojects { ... repositories { // Make sure that you have the following two repositories google() // Google's Maven repository mavenCentral() // Maven Central repository } }
モジュール (アプリ レベル) のGradle ファイル (通常は
<project>/<app-module>/build.gradle
) に、Google サービス プラグインを追加します。plugins { id 'com.android.application' // Add the Google services Gradle plugin id 'com.google.gms.google-services' ... }
アプリに Firebase SDK を追加する
モジュール (アプリ レベル) の Gradle ファイル(通常は
<project>/<app-module>/build.gradle
) で、Firebase Cloud Messaging Android ライブラリの依存関係を追加します。ライブラリのバージョン管理には、 Firebase Android BoMを使用することをお勧めします。Firebase Cloud Messaging で最適なエクスペリエンスを得るには、Firebase プロジェクトでGoogle アナリティクスを有効にし、Google アナリティクス用の Firebase SDK をアプリに追加することをお勧めします。
Java
dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:31.2.0') // Add the dependencies for the Firebase Cloud Messaging and Analytics libraries // When using the BoM, you don't specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-messaging' implementation 'com.google.firebase:firebase-analytics' }
Firebase Android BoMを使用すると、アプリは常に互換性のあるバージョンの Firebase Android ライブラリを使用します。
(代替) BoM を使用せずに Firebase ライブラリの依存関係を追加する
Firebase BoM を使用しないことを選択した場合は、依存関係の行で各 Firebase ライブラリ バージョンを指定する必要があります。
アプリで複数のFirebase ライブラリを使用する場合は、BoM を使用してライブラリ バージョンを管理することを強くお勧めします。これにより、すべてのバージョンに互換性が確保されます。
dependencies { // Add the dependencies for the Firebase Cloud Messaging and Analytics libraries // When NOT using the BoM, you must specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-messaging:23.1.1' implementation 'com.google.firebase:firebase-analytics:21.2.0' }
Kotlin+KTX
dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:31.2.0') // Add the dependencies for the Firebase Cloud Messaging and Analytics libraries // When using the BoM, you don't specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-messaging-ktx' implementation 'com.google.firebase:firebase-analytics-ktx' }
Firebase Android BoMを使用すると、アプリは常に互換性のあるバージョンの Firebase Android ライブラリを使用します。
(代替) BoM を使用せずに Firebase ライブラリの依存関係を追加する
Firebase BoM を使用しないことを選択した場合は、依存関係の行で各 Firebase ライブラリ バージョンを指定する必要があります。
アプリで複数のFirebase ライブラリを使用する場合は、BoM を使用してライブラリ バージョンを管理することを強くお勧めします。これにより、すべてのバージョンに互換性が確保されます。
dependencies { // Add the dependencies for the Firebase Cloud Messaging and Analytics libraries // When NOT using the BoM, you must specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-messaging-ktx:23.1.1' implementation 'com.google.firebase:firebase-analytics-ktx:21.2.0' }
Android プロジェクトを Gradle ファイルと同期します。
Android Gradle プラグイン (AGP) v4.2 以前を使用する Gradle ビルドでは、Java 8 サポートを有効にする必要があります。そうしないと、Firebase SDK を追加するときに、これらの Android プロジェクトでビルド エラーが発生します。
このビルドの失敗を修正するには、次の 2 つのオプションのいずれかに従います。
- エラー メッセージに記載されている
compileOptions
をアプリ レベルのbuild.gradle
ファイルに追加します。 - Android プロジェクトの
minSdkVersion
を 26 以上に増やします。
この FAQで、このビルドの失敗について詳しく学んでください。
- エラー メッセージに記載されている
クライアント アプリをトピックにサブスクライブする
クライアント アプリは、既存のトピックをサブスクライブするか、新しいトピックを作成できます。クライアント アプリが新しいトピック名 (Firebase プロジェクトにまだ存在しないもの) をサブスクライブすると、その名前の新しいトピックが FCM で作成され、その後、任意のクライアントがそれにサブスクライブできます。
トピックをサブスクライブするために、クライアント アプリは Firebase Cloud Messaging subscribeToTopic()
を FCM トピック名で呼び出します。このメソッドはTask
を返します。これを完了リスナーが使用して、サブスクリプションが成功したかどうかを判断できます。
Kotlin+KTX
Firebase.messaging.subscribeToTopic("weather") .addOnCompleteListener { task -> var msg = "Subscribed" if (!task.isSuccessful) { msg = "Subscribe failed" } Log.d(TAG, msg) Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show() }
Java
FirebaseMessaging.getInstance().subscribeToTopic("weather") .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { String msg = "Subscribed"; if (!task.isSuccessful()) { msg = "Subscribe failed"; } Log.d(TAG, msg); Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); } });
サブスクライブを解除するために、クライアント アプリは Firebase Cloud Messaging のunsubscribeFromTopic()
をトピック名で呼び出します。
トピック メッセージを受信して処理する
FCM は、他のダウンストリーム メッセージと同じ方法でトピック メッセージを配信します。
メッセージを受信するには、 FirebaseMessagingServiceを拡張するサービスを使用します。サービスはonMessageReceived
およびonDeletedMessages
コールバックをオーバーライドする必要があります。受信から 20 秒以内 (Android Marshmallow では 10 秒) 以内にメッセージを処理する必要があります。 onMessageReceived
を呼び出す前に発生した OS の遅延によっては、時間枠が短くなる場合があります。それ以降は、Android O のバックグラウンド実行制限など、さまざまな OS の動作により、作業を完了する能力が妨げられる可能性があります。詳細については、メッセージの優先度に関する概要を参照してください。
onMessageReceived
は、次の例外を除いて、ほとんどのメッセージ タイプに提供されます。
アプリがバックグラウンドにあるときに配信される通知メッセージ。この場合、通知はデバイスのシステム トレイに配信されます。ユーザーが通知をタップすると、デフォルトでアプリ ランチャーが開きます。
バックグラウンドで受信した場合、通知とデータ ペイロードの両方を含むメッセージ。この場合、通知はデバイスのシステム トレイに配信され、データ ペイロードはランチャー アクティビティのインテントのエクストラで配信されます。
要約すれば:
アプリの状態 | 通知 | データ | 両方 |
---|---|---|---|
前景 | onMessageReceived | onMessageReceived | onMessageReceived |
バックグラウンド | システムトレイ | onMessageReceived | 通知: システム トレイ データ: インテントのエクストラ。 |
アプリ マニフェストを編集する
FirebaseMessagingService
を使用するには、アプリ マニフェストに以下を追加する必要があります。
<service android:name=".java.MyFirebaseMessagingService" android:exported="false"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>
また、デフォルト値を設定して、通知の外観をカスタマイズすることをお勧めします。通知ペイロードに同等の値が設定されていない場合に適用されるカスタム デフォルト アイコンとカスタム デフォルト カラーを指定できます。
application
タグ内に次の行を追加して、カスタムのデフォルト アイコンとカスタム カラーを設定します。
<!-- Set custom default icon. This is used when no icon is set for incoming notification messages. See README(https://goo.gl/l4GJaQ) for more. --> <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_stat_ic_notification" /> <!-- Set color used with incoming notification messages. This is used when no color is set for the incoming notification message. See README(https://goo.gl/6BKBk7) for more. --> <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/colorAccent" />
Android では、カスタムのデフォルト アイコンが表示されます。
- Notifications composerから送信されたすべての通知メッセージ。
- 通知ペイロードに明示的にアイコンを設定しない通知メッセージ。
Android ではカスタムのデフォルト カラーを使用します。
- Notifications composerから送信されたすべての通知メッセージ。
- 通知ペイロードで明示的に色を設定しない通知メッセージ。
カスタムのデフォルト アイコンが設定されておらず、通知ペイロードにアイコンが設定されていない場合、Android は白でレンダリングされたアプリケーション アイコンを表示します。
onMessageReceived
オーバーライドする
メソッドFirebaseMessagingService.onMessageReceived
をオーバーライドすることで、受信したRemoteMessageオブジェクトに基づいてアクションを実行し、メッセージ データを取得できます。
Kotlin+KTX
override fun onMessageReceived(remoteMessage: RemoteMessage) { // TODO(developer): Handle FCM messages here. // Not getting messages here? See why this may be: https://goo.gl/39bRNJ Log.d(TAG, "From: ${remoteMessage.from}") // Check if message contains a data payload. if (remoteMessage.data.isNotEmpty()) { Log.d(TAG, "Message data payload: ${remoteMessage.data}") if (/* Check if data needs to be processed by long running job */ true) { // For long-running tasks (10 seconds or more) use WorkManager. scheduleJob() } else { // Handle message within 10 seconds handleNow() } } // Check if message contains a notification payload. remoteMessage.notification?.let { Log.d(TAG, "Message Notification Body: ${it.body}") } // Also if you intend on generating your own notifications as a result of a received FCM // message, here is where that should be initiated. See sendNotification method below. }
Java
@Override public void onMessageReceived(RemoteMessage remoteMessage) { // TODO(developer): Handle FCM messages here. // Not getting messages here? See why this may be: https://goo.gl/39bRNJ Log.d(TAG, "From: " + remoteMessage.getFrom()); // Check if message contains a data payload. if (remoteMessage.getData().size() > 0) { Log.d(TAG, "Message data payload: " + remoteMessage.getData()); if (/* Check if data needs to be processed by long running job */ true) { // For long-running tasks (10 seconds or more) use WorkManager. scheduleJob(); } else { // Handle message within 10 seconds handleNow(); } } // Check if message contains a notification payload. if (remoteMessage.getNotification() != null) { Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); } // Also if you intend on generating your own notifications as a result of a received FCM // message, here is where that should be initiated. See sendNotification method below. }
onDeletedMessages
オーバーライドする
状況によっては、FCM がメッセージを配信しないことがあります。これは、接続時に特定のデバイス上のアプリに対して保留中のメッセージが多すぎる (>100) 場合、またはデバイスが 1 か月以上 FCM に接続されていない場合に発生します。このような場合、 FirebaseMessagingService.onDeletedMessages()
へのコールバックを受け取ることがあります。アプリ インスタンスがこのコールバックを受け取ると、アプリ サーバーとの完全な同期を実行する必要があります。過去 4 週間以内にそのデバイスのアプリにメッセージを送信していない場合、FCM はonDeletedMessages()
を呼び出しません。バックグラウンド アプリで通知メッセージを処理する
アプリがバックグラウンドにある場合、Android は通知メッセージをシステム トレイに送信します。ユーザーが通知をタップすると、デフォルトでアプリ ランチャーが開きます。
これには、通知とデータ ペイロードの両方を含むメッセージ (および Notifications コンソールから送信されたすべてのメッセージ) が含まれます。このような場合、通知はデバイスのシステム トレイに配信され、データ ペイロードはランチャー アクティビティのインテントのエクストラで配信されます。
アプリへのメッセージ配信について詳しくは、 FCM レポート ダッシュボードを参照してください。このダッシュボードには、Apple および Android デバイスで送信および開封されたメッセージの数と、Android アプリの「インプレッション」(ユーザーが表示した通知) のデータが記録されています。
バックグラウンドで制限されたアプリ (Android P 以降)
FCM は、ユーザーによってバックグラウンドで制限されたアプリにメッセージを配信しない場合があります (設定 -> アプリと通知 -> [アプリ名] -> バッテリーなど)。アプリがバックグラウンド制限から削除されると、アプリへの新しいメッセージは以前と同じように配信されます。メッセージの紛失やその他のバックグラウンド制限の影響を防ぐために、 Android Vitalsの取り組みで挙げられている悪い動作を避けるようにしてください。これらの動作により、アプリのバックグラウンドを制限することを Android デバイスがユーザーに推奨する可能性があります。 isBackgroundRestricted()を使用して、アプリがバックグラウンドで制限されているかどうかを確認できます。送信リクエストの作成
トピックを作成したら、クライアント アプリ インスタンスをクライアント側のトピックにサブスクライブするか、サーバー APIを介してトピックにメッセージを送信できます。 FCM の送信リクエストを初めて作成する場合は、サーバー環境と FCMのガイドを参照して、重要な背景とセットアップ情報を確認してください。
バックエンドの送信ロジックで、次のように目的のトピック名を指定します。
Node.js
// The topic name can be optionally prefixed with "/topics/".
const topic = 'highScores';
const message = {
data: {
score: '850',
time: '2:45'
},
topic: topic
};
// Send a message to devices subscribed to the provided topic.
getMessaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
ジャワ
// The topic name can be optionally prefixed with "/topics/".
String topic = "highScores";
// See documentation on defining a message payload.
Message message = Message.builder()
.putData("score", "850")
.putData("time", "2:45")
.setTopic(topic)
.build();
// Send a message to the devices subscribed to the provided topic.
String response = FirebaseMessaging.getInstance().send(message);
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);
パイソン
# The topic name can be optionally prefixed with "/topics/".
topic = 'highScores'
# See documentation on defining a message payload.
message = messaging.Message(
data={
'score': '850',
'time': '2:45',
},
topic=topic,
)
# Send a message to the devices subscribed to the provided topic.
response = messaging.send(message)
# Response is a message ID string.
print('Successfully sent message:', response)
行け
// The topic name can be optionally prefixed with "/topics/".
topic := "highScores"
// See documentation on defining a message payload.
message := &messaging.Message{
Data: map[string]string{
"score": "850",
"time": "2:45",
},
Topic: topic,
}
// Send a message to the devices subscribed to the provided topic.
response, err := client.Send(ctx, message)
if err != nil {
log.Fatalln(err)
}
// Response is a message ID string.
fmt.Println("Successfully sent message:", response)
C#
// The topic name can be optionally prefixed with "/topics/".
var topic = "highScores";
// See documentation on defining a message payload.
var message = new Message()
{
Data = new Dictionary<string, string>()
{
{ "score", "850" },
{ "time", "2:45" },
},
Topic = topic,
};
// Send a message to the devices subscribed to the provided topic.
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
// Response is a message ID string.
Console.WriteLine("Successfully sent message: " + response);
残り
POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
"message":{
"topic" : "foo-bar",
"notification" : {
"body" : "This is a Firebase Cloud Messaging Topic Message!",
"title" : "FCM Message"
}
}
}
cURL コマンド:
curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
"message": {
"topic" : "foo-bar",
"notification": {
"body": "This is a Firebase Cloud Messaging Topic Message!",
"title": "FCM Message"
}
}
}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
トピックの組み合わせにメッセージを送信するには、条件を指定します。これは、ターゲット トピックを指定するブール式です。たとえば、次の条件は、 TopicA
とTopicB
またはTopicC
のいずれかにサブスクライブしているデバイスにメッセージを送信します。
"'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)"
FCM は、最初に括弧内の条件を評価し、次に式を左から右に評価します。上記の式では、単一のトピックにサブスクライブしているユーザーはメッセージを受信しません。同様に、 TopicA
に登録していないユーザーはメッセージを受信しません。これらの組み合わせはそれを受け取ります:
-
TopicA
とTopicB
-
TopicA
とTopicC
条件式には最大 5 つのトピックを含めることができます。
条件に送信するには:
Node.js
// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
const condition = '\'stock-GOOG\' in topics || \'industry-tech\' in topics';
// See documentation on defining a message payload.
const message = {
notification: {
title: '$FooCorp up 1.43% on the day',
body: '$FooCorp gained 11.80 points to close at 835.67, up 1.43% on the day.'
},
condition: condition
};
// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
getMessaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
ジャワ
// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
String condition = "'stock-GOOG' in topics || 'industry-tech' in topics";
// See documentation on defining a message payload.
Message message = Message.builder()
.setNotification(Notification.builder()
.setTitle("$GOOG up 1.43% on the day")
.setBody("$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.")
.build())
.setCondition(condition)
.build();
// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
String response = FirebaseMessaging.getInstance().send(message);
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);
パイソン
# Define a condition which will send to devices which are subscribed
# to either the Google stock or the tech industry topics.
condition = "'stock-GOOG' in topics || 'industry-tech' in topics"
# See documentation on defining a message payload.
message = messaging.Message(
notification=messaging.Notification(
title='$GOOG up 1.43% on the day',
body='$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
),
condition=condition,
)
# Send a message to devices subscribed to the combination of topics
# specified by the provided condition.
response = messaging.send(message)
# Response is a message ID string.
print('Successfully sent message:', response)
行け
// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
condition := "'stock-GOOG' in topics || 'industry-tech' in topics"
// See documentation on defining a message payload.
message := &messaging.Message{
Data: map[string]string{
"score": "850",
"time": "2:45",
},
Condition: condition,
}
// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
response, err := client.Send(ctx, message)
if err != nil {
log.Fatalln(err)
}
// Response is a message ID string.
fmt.Println("Successfully sent message:", response)
C#
// Define a condition which will send to devices which are subscribed
// to either the Google stock or the tech industry topics.
var condition = "'stock-GOOG' in topics || 'industry-tech' in topics";
// See documentation on defining a message payload.
var message = new Message()
{
Notification = new Notification()
{
Title = "$GOOG up 1.43% on the day",
Body = "$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.",
},
Condition = condition,
};
// Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
// Response is a message ID string.
Console.WriteLine("Successfully sent message: " + response);
残り
POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
"message":{
"condition": "'dogs' in topics || 'cats' in topics",
"notification" : {
"body" : "This is a Firebase Cloud Messaging Topic Message!",
"title" : "FCM Message",
}
}
}
cURL コマンド:
curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
"notification": {
"title": "FCM Message",
"body": "This is a Firebase Cloud Messaging Topic Message!",
},
"condition": "'dogs' in topics || 'cats' in topics"
}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
次のステップ
- サーバーを使用して、クライアント アプリ インスタンスをトピックにサブスクライブし、その他の管理タスクを実行できます。サーバーでトピックのサブスクリプションを管理するを参照してください。
- 複数のデバイスに送信するもう 1 つの方法 —デバイス グループ メッセージングの詳細