3. 左上隅にある設定アイコンをクリックしてください、プロジェクトの概要の隣にあります。
4. プロジェクトの設定を選択してください。
5. プロジェクトの設定内で、サービスアカウントに移動してください。
6. 新しい秘密鍵を生成をクリックしてください。
7. この操作により、秘密鍵が含まれるJSONファイルを含むサービスアカウントが生成されます。
9. FCM(Cloud Messaging)の控え名のセクションにあるFCM(Firebase Cloud Messaging) API(V1)がアクティブ化されていることを確認してください。
10. もし非活性化されている場合は、Firebase Cloud Messaging API (V1)の隣にある三つのドットのアイコンをクリックし、Google Cloud ConsoleでのAPI管理を選択した後、有効化をクリックしてください。
AndroidのクライアントアプリでFirebase Cloud Messaging (FCM)を設定する方法:
FCMが設定された後、以下の手順に従ってデバイスで通知の受信を開始します。
1. 以下のコードをアプリケーションレベルのマニフェストファイルに追加します。これにより、私たちはFirebaseより通知を受け取ることができます。
- <サービス android:名前='.NotificationFCMReceiver'
android:エクスポート済み='無効'>
<操作 android:名前='com。google。firebase。MESSAGING_EVENT' />
2. FirebaseMessagingServiceを拡張するクラスをあなたのアプリのプロジェクトに追加してください。以下に標準の言語に基づいたコードを参照してください:
For JAVA, 以下のコードを使用してください:
- インポート com。google。firebase。messaging。FirebaseMessagingService;
- インポート com。google。firebase。messaging。RemoteMessage;
- インポート com。Zoho。pagesense。android。PSNotification;
- 公開するクラス NotificationFCMReceiver extends FirebaseMessagingService {
- @Override
- 公開する 無効 onNewToken(@NonNull String s) {
- super。onNewToken(s);
- PSNotification。sendDeviceToken(s);
- }
- @Override
- 公開する 無効 onMessageReceived(@NonNull RemoteMessage remoteMessage) {
- super。onMessageReceived(remoteMessage);
- if(PSNotification。isFromPageSensePlatform(remoteMessage。getData())) {
PSNotification。showNotification(remoteMessage。getData(),
- com。Zoho。pagesense。android。R。drawable。notification_bg);
- }
- }
- }
KOTLINについては、次のコードを使用します:
- インポート com.google.firebase.messaging.FirebaseMessagingService
- インポート com.google.firebase.messaging.RemoteMessage
- インポート com.Zoho.pagesense.android.PSNotification
- クラス NotificationFCMReceiver : FirebaseMessagingService() {
- override fun onNewToken(s: String) {
- super.onNewToken(s)
- PSNotification.sendDeviceToken(s)
- }
- override fun onMessageReceived(remoteMessage: RemoteMessage) {
- super.onMessageReceived(remoteMessage)
- if (PSNotification.isFromPageSensePlatform(remoteMessage.data)) {
- PSNotification.showNotification(remoteMessage.data,
- com.Zoho.pagesense.android.R.drawable.notification_bg)
- }
- }
- }
- onNewTokenはデバイストークンが作成された際に呼び出されます。API PSNotification.sendDeviceToken(s)を使用してトークンをZoho PageSenseに送信します。
- onMessageReceivedは通知が受け取られたときに呼び出されます。ここでは、API PSNotification.isFromPageSensePlatform(remoteMessage.getData())を使用して通知がPagesenseから送信されたかどうかを確認する必要があります。その後、API PSNotification.showNotification(remoteMessage.getData()、com.Zoho.pagesense.android.R.drawable.notification_bg);をデータと通知のアイコンを送信して呼び出します。
ランタイムに必要な許可:
Android 12以上の場合、以下の権限が通知内の通話およびスヌーズボタンを処理するために有効でなければなりません。
-