Broadcast Receiverによるプッシュ受信、オープン、却下、およびキーと値のペアのカスタム処理
BroadcastReceiverプッシュ通知にカスタムを使用することは廃止されました。 subscribeToPushNotificationEvents()代わりに使用してください。
また、Braze はプッシュ通知の受信、開封、または却下時にカスタムインテントをブロードキャストします。これらのシナリオで特定のユースケース(カスタムのキーと値のペアを監視する必要がある場合や、ディープリンクの独自の処理が必要な場合など)がある場合は、カスタムを作成してこれらの意図に耳を傾ける必要があります。BroadcastReceiver
ステップ 1:放送受信機を登録する
カスタムを登録するとBroadcastReceiver、以下の画面で Braze のプッシュが開いて受信したインテントを聞くことができます。AndroidManifest.xml
1
2
3
4
5
6
7
<receiver android:name="YOUR-BROADCASTRECEIVER-NAME" android:exported="false" >
  <intent-filter>
    <action android:name="com.braze.push.intent.NOTIFICATION_RECEIVED" />
    <action android:name="com.braze.push.intent.NOTIFICATION_OPENED" />
    <action android:name="com.braze.push.intent.NOTIFICATION_DELETED" />
  </intent-filter>
</receiver>
ステップ 2:ブロードキャストレシーバーを作成
受信者は Braze によってブロードキャストされたインテントを処理し、その受信者でアクティビティを開始する必要があります。
BroadcastReceiveronReceive()サブクラス化してオーバーライドする必要があります。onReceive()このメソッドは Braze によってブロードキャストされたインテントをリッスンする必要があります。- プッシュ通知が到着すると、
NOTIFICATION_RECEIVEDインテントが受信されます。 - ユーザーがプッシュ通知をクリックすると、
NOTIFICATION_OPENEDインテントが受信されます。 - ユーザーがプッシュ通知を閉じる (スワイプする) と、
NOTIFICATION_DELETEDインテントが受信されます。 
- プッシュ通知が到着すると、
 - それぞれのケースでカスタムロジックを実行する必要があります。受信者がディープリンクを開く場合は、
com_braze_handle_push_deep_links_automaticallyfalseでに設定してディープリンクの自動開封を必ずオフにしてくださいbraze.xml。 
詳細なカスタムレシーバーの例については、次のコードスニペットを参照してください。
```ジャワ パブリッククラスのカスタムブロードキャストレシーバはブロードキャストレシーバを拡張します { プライベート・スタティック・ファイナル・ストリング・タグ = customBroadcastReceiver.class.getName ();
@Override パブリックボイドonReceive(コンテキストコンテキスト、インテントインテント){ String PushReceivedAction = Constants.Braze_push_intent_notification_Received; String notificationOpenedAction = Constants.Braze_push_intent_notification_open; String notificationDeletedAction = Constants.Braze_push_intent_notification_Deleted;
1
2
3
4
5
6
7
8
9
10
11
12
String action = intent.getAction();
Log.d(TAG, String.format("Received intent with action %s", action));
if (pushReceivedAction.equals(action)) {
  Log.d(TAG, "Received push notification.");
} else if (notificationOpenedAction.equals(action)) {
  BrazeNotificationUtils.routeUserWithNotificationOpenedIntent(context, intent);
} else if (notificationDeletedAction.equals(action)) {
  Log.d(TAG, "Received push notification deleted intent.");
} else {
  Log.d(TAG, String.format("Ignoring intent with unsupported action %s", action));
}   } } \`\`\`
``コトリン クラスカスタム放送受信機:ブロードキャストレシーバー () { onReceive でオーバーライドする (コンテキスト:コンテキスト、意図:意図) { val Push_ReceivedAction = Constant.Braze_Push_Intent_Notification_Received val NotificationOpenedAction = Constants.Braze_push_intent_notification_open val notificationDeletedAction = Constants.Braze_push_intent_notification_Deleted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
val action = intent.action
Log.d(TAG, String.format("Received intent with action %s", action))
when (action) {
  pushReceivedAction -> {
    Log.d(TAG, "Received push notification.")
  }
  notificationOpenedAction -> {
    BrazeNotificationUtils.routeUserWithNotificationOpenedIntent(context, intent)
  }
  notificationDeletedAction -> {
    Log.d(TAG, "Received push notification deleted intent.")
  }
  else -> {
    Log.d(TAG, String.format("Ignoring intent with unsupported action %s", action))
  }
}   }
companion object { private val TAG = CustomBroadcastReceiver::class.java.name } } ```
通知アクションボタンでは、BRAZE_PUSH_INTENT_NOTIFICATION_OPENEDopens appdeep linkまたはアクションの付いたボタンがクリックされたときにインテントが起動します。ディープリンクとエクストラの処理は変わりません。closeBRAZE_PUSH_INTENT_NOTIFICATION_OPENEDアクション付きのボタンはインテントを起動せず、通知を自動的に閉じます。
ステップ 3:カスタムのキーと値のペアへのアクセス
ダッシュボードまたはメッセージAPIを介して送信されたカスタムキーと値のペアは、任意の目的でカスタムブロードキャストレシーバーからアクセスできます。
```ジャワ //インテントは、カスタムブロードキャストレシーバーが受信する Braze プッシュインテントです。 String DeepLink = intent.getStringExtra (Constants.Braze_push_deep_link_key);
//インテントから抽出されたエクストラバンドルには、カスタムのキーと値のペアがすべて含まれています。 バンドルエクストラ = intent.getBundleExtra (Constants.Braze_push_Extras_key);
//Extras バンドルから特定のキーと値のペアを取得する例。 String MyExtra = Extras.GetString (「my_key」); ``
``コトリン //インテントは、カスタムブロードキャストレシーバーが受信する Braze プッシュインテントです。 val DeepLink = intent.GetStringExtra (Constants.Braze_push_deep_link_key)
//インテントから抽出されたエクストラバンドルには、カスタムのキーと値のペアがすべて含まれています。 val extras = intent.getBundleExtra (Constants.Braze_push_Extras_key)
//Extras バンドルから特定のキーと値のペアを取得する例。 val MyExtra = Extras.GetString (「my_key」) ``
Braze プッシュデータキーに関するドキュメントについては、Android SDK を参照してください。
   Edit this page on GitHub