Adobe Mobile Services UI で設定したディープリンク URL は、プッシュペイロードの adb_deeplink キーに含まれます。
URL は、FirebaseMessagingService
の remoteMessage.getData().get("adb_deeplink")
を呼び出すことで取得できます。
ペイロードにディープリンク URL が含まれているかどうかに応じて、異なるインテントを定義できます。
次のどちらかのタスクを実行します。
ディープリンク URL がプッシュペイロードに含まれている場合、その URL で ACTION_VIEW
インテントを作成します。
ユーザーがプッシュメッセージをクリックすると、ディープリンクがトリガーされます。
ディープリンク URL がプッシュペイロードで でない場合は、アクティビティの 1 つを開くインテントを作成します。
FirebaseMessagingService
から拡張されるクラスの実装例を示します。
public void onMessageReceived(RemoteMessage message) {
Map<String, String> data = message.getData();
String messageStr = data.get("message");
String deepLink = data.get("adb_deeplink");
sendNotification(deepLink, messageStr, data);
}
private void sendNotification(String deeplink, String message, Map<String, String> data) {
Intent intent;
if (deeplink!=null) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(deeplink));
} else {
intent = new Intent(this, MainActivity.class);
}
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//put the data map into the intent to track clickthroughs
Bundle pushData = new Bundle();
Set<String> keySet = data.keySet();
for (String key : keySet) {
pushData.putString(key, data.get(key));
}
intent.putExtras(pushData);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setContentTitle("FCM Deep Link Push")
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager)getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}