1

アンドロイドアプリのFirebase通知を実装しようとしています。Firebase通知を使用してダイナミックリンクを開くにはどうすればよいですか?

私はまた、アプリケーションでダイナミックリンクを実装しました。

しかし、通知をクリックすると特定の動的リンクが開くように、動的リンクを使用して通知を送信する方法はわかりません。私は、テキスト通知を送るオプションしか見ることができません。

回避策はありますか、これはFCMの制限ですか?

答えて

7

現在、コンソールがサポートしていないため、通知のカスタムデータをサーバー側で送信する必要があります。 (カスタムキーと値のペアを使用すると、アプリがバックグラウンドモードになっているときにも通知が表示されません)。詳細はこちらhttps://firebase.google.com/docs/cloud-messaging/server

独自のApp Serverをインストールしたら、通知のカスタムデータセクションにDeep Link URLを含めることができます。

FirebaseMessagingServiceの実装では、ペイロードを見てそこからURLを取得し、そのディープリンクURLを使用するカスタムインテントを作成する必要があります。

私は現在DeepLinkActivityへのデータとリンクを設定でき、リンク処理を行うので、この状況ではうまく動作するAirBnbのディープリンクディスパッチャライブラリ(https://github.com/airbnb/DeepLinkDispatch)を使用しています。以下の例では、サーバーからのペイロードをDeepLinkNotificationというオブジェクトに変換します。このオブジェクトにはURLフィールドが含まれています。

private void sendDeepLinkNotification(final DeepLinkNotification notification) { 
    ... 
    Intent mainIntent = new Intent(this, DeepLinkActivity.class); 
    mainIntent.setAction(Intent.ACTION_VIEW); 
    mainIntent.setData(Uri.parse(notification.getUrl())); 
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); 
    stackBuilder.addNextIntent(mainIntent); 
    PendingIntent pendingIntent = stackBuilder.getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT); 

    NotificationCompat.Builder builder = buildBasicNotification(notification); 
    builder.setContentIntent(pendingIntent); 

    notificationManager.notify(notificationId, builder.build()); 
} 

DeepLinkActivity:

@DeepLinkHandler 
public class DeepLinkActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     dispatch();  
    } 

    private void dispatch() { 
     DeepLinkResult deepLinkResult = DeepLinkDelegate.dispatchFrom(this); 
     if (!deepLinkResult.isSuccessful()) { 
      Timber.i("Deep link unsuccessful: %s", deepLinkResult.error()); 
      //do something here to handle links you don't know what to do with 
     } 
     finish(); 
    } 
} 

この実装を行うことで、あなたも、あなたはただのURLでIntent.ACTION_VIEWに意図を設定している場合に比べて取り扱いカントのリンクを開くことはありません。

+0

ありがとうございました – PedroAGSantos

関連する問題