FCM HTTP v1 API থেকে AndroidConfigV2-এ মাইগ্রেট করা

FCM AndroidConfigV2 ব্যবহার করে, আপনি Android ডিভাইসে সময়মতো বিজ্ঞপ্তি ডেলিভারি এবং সহজ API-এর মাধ্যমে ইনটেন্ট-চালিত মেসেজ পাঠাতে পারবেন।

এই গাইডে AndroidConfig থেকে AndroidConfigV2-এ আপনার ব্যাকএন্ড পাঠানোর অনুরোধ কীভাবে মাইগ্রেট করবেন এবং কীভাবে আপনার Android অ্যাপ্লিকেশন ক্লায়েন্টকে পুরনো onMessageReceived হ্যান্ডলিং থেকে নতুন v2 ক্লায়েন্ট কলব্যাক onNotificationReceived এবং onBackgroundSyncReceived-এ আপডেট করবেন তা কভার করে।

AndroidConfigV2-এ নতুন কী আছে

FCM AndroidConfigV2 API দুই ধরনের মেসেজ প্রবর্তন করে ডেভেলপারদের অভিজ্ঞতাকে সহজ করে তোলে:

  • RemoteNotification: সমস্ত FCM মেসেজের জন্য সাজেস্ট করা হয়েছে যা জরুরি, সময়-সংবেদনশীল ব্যবহারকারী-দৃশ্যমান বিজ্ঞপ্তি দেখায়। এইসব মেসেজ ব্যাটারি সাশ্রয় সংক্রান্ত যেকোনও ব্যবস্থা বাইপাস করে এবং কোনও দেরি না করেই ডেলিভার করা হয়। ডিভাইসে, FCM SDK এবং Google Play পরিষেবা Android-এর NotificationManager-এ বিজ্ঞপ্তি পোস্ট করার মালিকানা গ্রহণ করে।
  • BackgroundSync: ব্যাকগ্রাউন্ড সিঙ্ক ও অ্যাপের স্ট্যাটাস আপডেট করার জন্য জরুরি নয় এমন ডেটা মেসেজ। ব্যাটারির আয়ু অপ্টিমাইজ করতে, ডেলিভারি ব্যাচ করা বা দেরি করা হতে পারে।
বৈশিষ্ট্য লিগ্যাসি (AndroidConfig v1) নতুন (AndroidConfigV2)
কনফিগারেশন ফিল্ড message.android message.android_v2
অগ্রাধিকারের সংজ্ঞা অনুপযুক্ত priority: "high" বা priority: "normal" ইউনিয়ন টাইপ দ্বারা বোঝানো হয়েছে (জরুরি সতর্কতার জন্য remote_notification বনাম জরুরি নয় এমন সিঙ্কের জন্য background_sync)
বিজ্ঞপ্তি পোস্ট করা অ্যাপ ম্যানুয়ালি NotificationManager.notify()-এ কল করে FCM SDK এবং GMS Core সরাসরি বা NotificationResponse ব্যবহার করে পোস্ট করে
ক্লায়েন্ট কলব্যাক • onMessageReceived(RemoteMessage)
• onDeletedMessages()
• onNotificationReceived(RemoteMessage)
• onBackgroundSyncReceived(RemoteMessage)
• onDeletedMessages()
Collapsibility বিভিন্ন; স্পষ্ট সেটিং প্রয়োজন দুটি মেসেজের ধরনই আড়াল করা বা আড়াল না করা যেতে পারে (ডিফল্ট হিসেবে আড়াল করা যায় না)

AndroidConfigV2-কে অনুরোধ পাঠানোর অনুমতি দিন

আপনি Google অ্যাপ্লিকেশন ডিফল্ট ক্রেডেনশিয়াল বা অ্যাডমিন SDK ব্যবহার করে আপনার Firebase পরিষেবা অ্যাকাউন্ট থেকে প্রাপ্ত OAuth 2.0 অ্যাক্সেস টোকেন ব্যবহার করা চালিয়ে যেতে পারেন, এবং HTTP v1 messages:send এন্ডপয়েন্টে POST অনুরোধ পাঠাতে পারেন।

আপনি যদি Firebase পরিষেবা অ্যাকাউন্ট ব্যবহার না করেন, তাহলে আপনার নির্দিষ্ট অ্যাকাউন্টকে Firebase Cloud Messaging API Admin ভূমিকায় (roles/firebase.messagingAdmin) অ্যাসাইন করতে ভুলবেন না এবং অ্যাক্সেস টোকেন মিন্ট করার সময় https://www.googleapis.com/auth/firebase.messaging OAuth 2.0 স্কোপের জন্য অনুরোধ করুন:

POST https://fcm.googleapis.com/v1/projects/YOUR_PROJECT_ID/messages:send HTTP/1.1
Authorization: Bearer YOUR_OAUTH_ACCESS_TOKEN
Content-Type: application/json

সার্ভার পাঠানোর অনুরোধ আপডেট করুন (REST)

REST API ব্যবহার করে AndroidConfigV2 অনুরোধ পাঠাতে, আপনার অনুরোধের মূল অংশে android অবজেক্টটি android_v2 দিয়ে প্রতিস্থাপন করুন। android_v2-এর মধ্যে, সাধারণ প্যারামিটার (যেমন ttl, collapse_key, data এবং restricted_package_name) নির্দিষ্ট করুন এবং নিম্নলিখিত ইউনিয়ন ফিল্ডের মধ্যে একটি প্রদান করুন: remote_notification অথবা background_sync।

RemoteNotification মেসেজ পাঠান

ব্যবহারকারী নিজে ইন্টার‌্যাক্ট করতে পারেন এমন জরুরি বিজ্ঞপ্তি পাঠাতে, remote_notification অবজেক্ট ও তার সাজেস্ট করা notification পেলোড অন্তর্ভুক্ত করুন। ডিফল্ট হিসেবে mutable_content মিথ্যা হিসেবে সেট করা থাকে। GMS Core ব্যাকগ্রাউন্ড অ্যাপ কোড এক্সিকিউট না করেই সিস্টেম ট্রেতে বিজ্ঞপ্তিটি অবিলম্বে রেন্ডার এবং পোস্ট করে।

সম্পূর্ণ HTTP অনুরোধ JSON স্যাম্পেল (অটো-রেন্ডার করা বিজ্ঞপ্তি)

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": {
    "token": "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification": {
      "title": "FCM Message",
      "body": "This is an FCM notification message!"
    },
    "android_v2": {
      "ttl": "3600s",
      "remote_notification": {
        "mutable_content": false,
        "notification": {
          "title": "Order update",
          "body": "Your order has been shipped!",
          "icon": "ic_notification_custom",
          "sound": "default",
          "tag": "alert_tag_1",
          "id": 100
        }
      }
    }
  }
}

পরিবর্তনযোগ্য কন্টেন্ট সহ RemoteNotification পাঠান

আপনার অ্যাপ্লিকেশনকে ডিভাইসে বিজ্ঞপ্তি দেখানোর আগে সেটি পরিবর্তন করতে হলে, remote_notification-এর মধ্যে mutable_content: true সেট করুন। এটি GMS Core-কে আপনার ক্লায়েন্ট অ্যাপ্লিকেশনের সাথে বাইন্ড করতে এবং onNotificationReceived()-কে ইনভোক করতে নির্দেশ দেয়। আপনি যখন এন্ড-টু-এন্ড এনক্রিপ্টেড পেলোড ডিক্রিপ্ট করতে, ব্যবহারকারীর অবতার অ্যাটাচ করতে অথবা স্ট্রিং লোকালাইজ করতে চান, তখন এটি সহায়ক হয়।

mutable_content, true হলেও remote_notification-এর মধ্যে notification অবজেক্ট অন্তর্ভুক্ত করতে ভুলবেন না। ক্লায়েন্ট কলব্যাক টাইম-আউট হয়ে গেলে বা সাপ্রেশন সীমা পেরিয়ে গেলে, GMS Core এই notification অবজেক্টকে ফলব্যাক বিজ্ঞপ্তি হিসেবে ব্যবহার করে।

আপনি যদি লিগ্যাসি v1 ডেটা মেসেজ থেকে মাইগ্রেট করেন এবং FCM-এর মাধ্যমে পুরনো v1 ক্লায়েন্ট ইনস্টলেশনে পিওর ডেটা মেসেজ হিসেবে পেলোড ডেলিভার করতে চান, তাহলে remote_notification-এর মধ্যে use_as_v1_data_message: true সেট করুন।

সম্পূর্ণ HTTP অনুরোধ JSON স্যাম্পেল

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": {
    "token": "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "data": {
      "encrypted_content": "U2FsdGVkX19vN2m+",
      "sender_id": "user_98124"
    },
    "android_v2": {
      "ttl": "3600s",
      "remote_notification": {
        "mutable_content": true,
        "use_as_v1_data_message": true,
        "notification": {
          "title": "New message",
          "body": "You have a new message",
          "tag": "chat_alert",
          "id": 1001
        }
      }
    }
  }
}

BackgroundSync মেসেজ পাঠান

ব্যাকগ্রাউন্ড ডেটা সিঙ্ক, সাইলেন্ট স্টেট আপডেট বা অ্যাপ ব্যাজ বা উইজেট আপডেট করার জন্য কোনও জরুরি নয় এমন মেসেজ পাঠাতে, background_sync অবজেক্ট ব্যবহার করুন। ব্যবহারকারী-দৃশ্যমান বিজ্ঞপ্তি পোস্ট করতে এই মেসেজগুলি ব্যবহার করবেন না, কারণ ডিভাইসের ব্যাটারির আয়ু অপ্টিমাইজ করার জন্য এগুলি ব্যাচ করা বা বিলম্বিত হতে পারে।

সম্পূর্ণ HTTP অনুরোধ JSON স্যাম্পেল

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": {
    "token": "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "data": {
      "score": "FETCH_UPDATES",
      "sync_action": "FETCH_UPDATES"
    },
    "android_v2": {
      "ttl": "86400s",
      "collapse_key": "app_state_sync",
      "background_sync": {}
    }
  }
}

Android ক্লায়েন্ট কলব্যাক আপডেট করুন

Android-এ AndroidConfigV2 মেসেজ পেতে, লেটেস্ট firebase-messaging SDK ব্যবহার করার জন্য আপনার অ্যাপ আপগ্রেড করুন। onNotificationReceived() ও onBackgroundSyncReceived() প্রয়োগ করে FirebaseMessagingService-এর মাধ্যমে আপনার পরিষেবা আপডেট করুন।

EAP SDK ইনস্টল করুন

EAP চলাকালীন, firebase-messaging v2 SDK, Google-এর পাবলিক Maven রিপোজিটরির পরিবর্তে লোকাল Maven রিপোজিটরি আর্কাইভ হিসেবে ডিস্ট্রিবিউট করা হয়।

  1. নিম্নলিখিত বিকল্পগুলির মধ্যে একটি ব্যবহার করে আপনার Android প্রোজেক্টের (<project-root>/m2repository) রুট ডিরেক্টরিতে firebase-messaging:26.1.0-eap01 সহ m2repository ডিরেক্টরি যোগ করুন:

    1. বিকল্প ক: আগে থেকে তৈরি করা আর্কাইভ ডাউনলোড করুন: FirebaseMessaging_26.1.0-eap01.zip ডাউনলোড করুন এবং আপনার Android প্রোজেক্টের (<project-root>/m2repository) রুট ডিরেক্টরিতে m2repository ডিরেক্টরি এক্সট্র্যাক্ট করুন।
    2. বিকল্প খ: Gradle-এর সাহায্যে GitHub থেকে তৈরি করুন: firebase/firebase-android-sdk-এর feature/fcm-android-config-v2-eap ব্রাঞ্চ ক্লোন করুন, লোকাল Maven রিপোজিটরি তৈরি করুন এবং তৈরি করা build/m2repository ডিরেক্টরি আপনার Android প্রোজেক্ট রুটে কপি করুন:

      git clone --branch feature/fcm-android-config-v2-eap --single-branch \
        https://github.com/firebase/firebase-android-sdk.git
      cd firebase-android-sdk
      ./gradlew -PprojectsToPublish="firebase-messaging" firebasePublish
      cp -R build/m2repository /path/to/your/android-project/m2repository
      
  2. আপনার প্রোজেক্ট-লেভেল settings.gradle.kts (বা settings.gradle)-এ, আপনার repositories ব্লকের উপরে, google()-এর উপরে লোকাল m2repository ডিরেক্টরি যোগ করুন:

    Kotlin

    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            maven { url = uri("${rootDir}/m2repository") }
            google()
            mavenCentral()
        }
    }
    

    Groovy

    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            maven { url "${rootDir}/m2repository" }
            google()
            mavenCentral()
        }
    }
    
  3. আপনার মডিউল-লেভেল app/build.gradle.kts (বা app/build.gradle)-এ, আপনার firebase-messaging ডিপেন্ডেন্সি 26.1.0-eap01-এ আপডেট করুন:

    Kotlin

    dependencies {
        implementation("com.google.firebase:firebase-messaging:26.1.0-eap01")
    }
    

    Groovy

    dependencies {
        implementation 'com.google.firebase:firebase-messaging:26.1.0-eap01'
    }
    
  4. Gradle ফাইলের সাথে আপনার প্রোজেক্ট সিঙ্ক করুন।

onNotificationReceived-এর মাধ্যমে RemoteNotifications ম্যানেজ করুন

AndroidConfigV2-এর সাথে, RemoteNotification মেসেজ দেখানো হয় যদি না mutable_content-কে সত্য হিসেবে সেট করা হয় অথবা onNotificationReceived()-এ সেগুলিকে স্পষ্টভাবে সাইলেন্স করা হয়।

mutable_content: true-এর সাথে RemoteNotification এলে, GMS Core আপনার অ্যাপ্লিকেশনের সাথে বাইন্ড করে এবং onNotificationReceived()-কে কল করে। আপনার পদ্ধতিকে অবশ্যই ২০ সেকেন্ডের মধ্যে NotificationResponse রিটার্ন করতে হবে।

পরিবর্তিত বিজ্ঞপ্তি ফেরত দেওয়া

NotificationResponse.create-এ পাস করা Notification অবজেক্ট, সার্ভারের remote_notification.notification ফলব্যাক পেলোড প্রপার্টিকে প্রতিস্থাপন করে, যা পাঠানোর অনুরোধে উল্লেখ করা থাকে। পাঠানো অনুরোধ থেকে ভ্যালু রাখতে, অন-ডিভাইস পরিবর্তন প্রয়োগ করার সময় message.notification (Java-তে message.getNotification()) থেকে সেগুলি পড়ুন:

Kotlin

import androidx.core.app.NotificationCompat
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.NotificationResponse
import com.google.firebase.messaging.RemoteMessage

class MyFirebaseMessagingService : FirebaseMessagingService() {

    override fun onNotificationReceived(message: RemoteMessage): NotificationResponse {
        val serverNotif = message.notification
        val channelId = serverNotif?.channelId ?: "default_channel"
        // Keep the server-defined title unchanged, or fall back to default
        val title = serverNotif?.title ?: "New message"
        // Modify the notification body on-device (for example, decrypting data)
        val decryptedBody = decryptPayload(message.data["encrypted_content"])

        val builder = NotificationCompat.Builder(this, channelId)
            .setSmallIcon(R.drawable.ic_stat_notification)
            .setContentTitle(title)
            .setContentText(decryptedBody)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setAutoCancel(true)

        // Return the response for the open-source FCM SDK to post to the Android platform
        return NotificationResponse.create("optional_tag", 100, builder.build())
    }
}

Java

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.google.firebase.messaging.NotificationResponse;
import androidx.core.app.NotificationCompat;

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public NotificationResponse onNotificationReceived(RemoteMessage message) {
        RemoteMessage.Notification serverNotif = message.getNotification();
        String channelId = (serverNotif != null && serverNotif.getChannelId() != null)
                ? serverNotif.getChannelId()
                : "default_channel";
        // Keep the server-defined title unchanged, or fall back to default
        String title = (serverNotif != null && serverNotif.getTitle() != null)
                ? serverNotif.getTitle()
                : "New message";
        // Modify the notification body on-device (for example, decrypting data)
        String decryptedBody = decryptPayload(message.getData().get("encrypted_content"));

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId)
                .setSmallIcon(R.drawable.ic_stat_notification)
                .setContentTitle(title)
                .setContentText(decryptedBody)
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setAutoCancel(true);

        // Return the response for the open-source FCM SDK to post to the Android platform
        return NotificationResponse.create("optional_tag", 100, builder.build());
    }
}

বিজ্ঞপ্তি দমন করুন

ব্যবহারকারীর কাছে প্রাসঙ্গিক স্ক্রিন বা চ্যাট এখন অ্যাক্টিভ থাকলে, আপনি NotificationResponse.suppress() রিটার্ন করে বিজ্ঞপ্তি বন্ধ করতে পারবেন:

Kotlin

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ProcessLifecycleOwner

override fun onNotificationReceived(message: RemoteMessage): NotificationResponse {
    val chatId = message.data["chat_id"]
    val isAppForeground = ProcessLifecycleOwner.get()
        .lifecycle
        .currentState
        .isAtLeast(Lifecycle.State.STARTED)

    if (isAppForeground && chatRepository.isConversationActive(chatId)) {
        // Suppress notification display because the user is actively viewing this chat
        return NotificationResponse.suppress()
    }

    val builder = buildNotificationForChat(message)
    return NotificationResponse.create("chat_tag", 101, builder.build())
}

Java

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.ProcessLifecycleOwner;

@Override
public NotificationResponse onNotificationReceived(RemoteMessage message) {
    String chatId = message.getData().get("chat_id");
    boolean isAppForeground = ProcessLifecycleOwner.get()
            .getLifecycle()
            .getCurrentState()
            .isAtLeast(Lifecycle.State.STARTED);

    if (isAppForeground && chatRepository.isConversationActive(chatId)) {
        // Suppress notification display because the user is actively viewing this chat
        return NotificationResponse.suppress();
    }

    NotificationCompat.Builder builder = buildNotificationForChat(message);
    return NotificationResponse.create("chat_tag", 101, builder.build());
}

বিজ্ঞপ্তি স্ট্রিম করুন বা পুরনো সতর্কতা বাতিল করুন (FcmNotificationManager)

একটি ইনকামিং পুশের জন্য একাধিক বিজ্ঞপ্তি পোস্ট করতে হলে অথবা নতুন বিজ্ঞপ্তি দেখানোর আগে পুরনো বিজ্ঞপ্তি বাতিল করতে হলে, FcmNotificationManager ব্যবহার করুন:

Kotlin

override fun onNotificationReceived(message: RemoteMessage): NotificationResponse {
    // Retrieve the scoped manager for this message execution
    val manager = getFcmNotificationManager(message)

    // 1. Cancel an outdated notification right away
    manager.cancelNow("message_tag", 50)

    // 2. Post the item notification immediately
    val itemNotif = NotificationCompat.Builder(this, "chat_channel")
        .setSmallIcon(R.drawable.ic_message)
        .setContentTitle("Alex")
        .setContentText(message.data["text"])
    manager.postNow("item_tag", 51, itemNotif.build())

    // 3. Post a group summary notification
    val summaryNotif = NotificationCompat.Builder(this, "chat_channel")
        .setSmallIcon(R.drawable.ic_message)
        .setContentTitle("New Conversations")
        .setGroupSummary(true)
    manager.postNow("summary_tag", 52, summaryNotif.build())

    // 4. Return finished() to complete the streaming workflow
    return manager.finished()
}

Java

@Override
public NotificationResponse onNotificationReceived(RemoteMessage message) {
    // Retrieve the scoped manager for this message execution
    FcmNotificationManager manager = getFcmNotificationManager(message);

    // 1. Cancel an outdated notification right away
    manager.cancelNow("message_tag", 50);

    // 2. Post the item notification immediately
    NotificationCompat.Builder itemNotif = new NotificationCompat.Builder(this, "chat_channel")
            .setSmallIcon(R.drawable.ic_message)
            .setContentTitle("Alex")
            .setContentText(message.getData().get("text"));
    manager.postNow("item_tag", 51, itemNotif.build());

    // 3. Post a group summary notification
    NotificationCompat.Builder summaryNotif = new NotificationCompat.Builder(this, "chat_channel")
            .setSmallIcon(R.drawable.ic_message)
            .setContentTitle("New Conversations")
            .setGroupSummary(true);
    manager.postNow("summary_tag", 52, summaryNotif.build());

    // 4. Return finished() to complete the streaming workflow
    return manager.finished();
}

onBackgroundSyncReceived ব্যবহার করে BackgroundSync মেসেজ ম্যানেজ করুন

Android-এ BackgroundSyncটি মেসেজ প্রসেস করতে, onBackgroundSyncReceived() ব্যবহার করুন:

Kotlin

override fun onBackgroundSyncReceived(message: RemoteMessage) {
    val syncCommand = message.data["sync_action"]

    try {
        // Perform local database synchronization or cache refresh
        AppDataRepository.getInstance(applicationContext).syncWithServer(syncCommand)
    } catch (e: Exception) {
        Log.e("FCM", "Background sync operation failed", e)
    }
    // Execution completes -> GMS Core marks the message as handled and unbinds.
}

Java

@Override
public void onBackgroundSyncReceived(RemoteMessage message) {
    String syncCommand = message.getData().get("sync_action");

    try {
        // Perform local database synchronization or cache refresh
        AppDataRepository.getInstance(getApplicationContext()).syncWithServer(syncCommand);
    } catch (Exception e) {
        Log.e("FCM", "Background sync operation failed", e);
    }
    // Execution completes -> GMS Core marks the message as handled and unbinds.
}

onDeletedMessages ব্যবহার করে বাকি থাকা মেসেজ মুছে ফেলার বিষয়টি ম্যানেজ করুন

কিছু পরিস্থিতিতে, যেমন কোনও ডিভাইস দীর্ঘ সময় ধরে FCM-এর সাথে কানেক্ট না থাকলে বা সার্ভার কিউ ভর্তি থাকলে, FCM ডেলিভারি করার আগে বাকি থাকা মেসেজ মুছে দিতে পারে। এইসব ক্ষেত্রে, ওভাররাইড onDeletedMessages():

Kotlin

override fun onDeletedMessages() {
    // Perform a full state synchronization with your app server
    AppDataRepository.getInstance(applicationContext).scheduleFullSync()
}

Java

@Override
public void onDeletedMessages() {
    // Perform a full state synchronization with your app server
    AppDataRepository.getInstance(getApplicationContext()).scheduleFullSync();
}

নির্দিষ্ট অ্যাপ মাইগ্রেট করা

এন্ড-টু-এন্ড এনক্রিপ্টেড (E2EE) বিজ্ঞপ্তি ডেলিভার করা

RemoteNotification ব্যবহার করে এন্ড-টু-এন্ড এনক্রিপ্টেড বিজ্ঞপ্তি ডেলিভার করার সময়, ডিক্রিপ্ট করা বিজ্ঞপ্তির কন্টেন্ট আপনার অ্যাপ ও Android প্ল্যাটফর্মে থাকে:

  1. মিউটেবল বিজ্ঞপ্তি ডেলিভার করা: আপনার সার্ভার RemoteNotification-এর সাথে mutable_content: true, data-এ এনক্রিপ্ট করা পেলোড এবং একটি সাধারণ আনএনক্রিপ্টেড ব্যাক-আপ notification পাঠায়। GMS Core আপনার অ্যাপের মধ্যে ওপেন-সোর্স FCM SDK-তে এনক্রিপ্ট করা মেসেজ ডেলিভার করে।
  2. ডিক্রিপ্ট করে বিজ্ঞপ্তি ফেরত পাঠানো: FCM SDK onNotificationReceived()-কে ইনভোক করে। আপনার অ্যাপ স্থানীয়ভাবে পেলোড ডিক্রিপ্ট করে, চূড়ান্ত ডিক্রিপ্ট করা Android Notification তৈরি করে এবং NotificationResponse বা FcmNotificationManager ব্যবহার করে ওপেন-সোর্স FCM SDK-তে এটি ফেরত পাঠায়।
  3. FCM ওপেন সোর্স SDK ডিক্রিপ্ট করা বিজ্ঞপ্তি সরাসরি Android প্ল্যাটফর্ম NotificationManager API-তে পোস্ট করে এবং ডেলিভারি সংক্রান্ত তথ্য দেখার জন্য শুধুমাত্র বিজ্ঞপ্তির মেটাডেটা, যেমন বিজ্ঞপ্তি আইডি ও টাইমস্ট্যাম্প GMS Core-এ ফেরত পাঠায়। ডিক্রিপ্ট করা কন্টেন্ট কখনই GMS Core-এ পাঠানো হয় না।
  4. প্রয়োজন হলে ব্যাক-আপ সংক্রান্ত বিজ্ঞপ্তি পোস্ট করা: আপনার অ্যাপ ২০ সেকেন্ডের টাইম-আউটের মধ্যে উত্তর দিতে না পারলে অথবা ব্যাকগ্রাউন্ড সাপ্রেশন সীমা অতিক্রম করলে, GMS Core সরাসরি Android প্ল্যাটফর্মে জেনেরিক ব্যাক-আপ notification পোস্ট করে।

আর্কিটেকচার ডায়াগ্রাম, GMS Core, ওপেন-সোর্স FCM SDK, আপনার অ্যাপ এবং Android প্ল্যাটফর্ম NotificationManager API-এর মধ্যে ৪-ধাপের এন্ড-টু-এন্ড এনক্রিপ্টেড বিজ্ঞপ্তি ডেলিভারি ফ্লো দেখাচ্ছে।

বিজ্ঞপ্তি বন্ধ করা ও টাইমআউট সম্পর্কে বোঝা

Android ইকোসিস্টেম জুড়ে নির্ভরযোগ্য ডেলিভারি বজায় রাখতে, GMS Core RemoteNotification মেসেজ ম্যানেজ করার সময় প্রসেসিং টাইমআউট এবং বিজ্ঞপ্তি দমন করার সীমা প্রয়োগ করে:

প্রসেসিং টাইমআউট

mutable_content-কে true-এ সেট করা হলে, আপনার onNotificationReceived() পদ্ধতিকে অবশ্যই ২০ সেকেন্ডের মধ্যে NotificationResponse ফিরিয়ে দিতে হবে। এক্সিকিউশন এই থ্রেশহোল্ড অতিক্রম করলে, কলব্যাক বাতিল করা হয় এবং GMS Core অটোমেটিক remote_notification.notification পেলোড থেকে রেন্ডার করা একটি ফলব্যাক বিজ্ঞপ্তি পোস্ট করে।

বিজ্ঞপ্তি দমন করার হার

যেহেতু RemoteNotification মেসেজ ব্যবহারকারীদের অবিলম্বে সতর্ক করার জন্য Doze বিধিনিষেধ বাইপাস করে এবং দেরি না করে ডেলিভার করা হয়, তাই অ্যাপ্লিকেশনগুলি থেকে প্রাপ্ত RemoteNotification মেসেজের জন্য বিজ্ঞপ্তি দেখাবে বলে আশা করা হয়।

ব্যাকগ্রাউন্ডে চলার সময় প্রতিটি অ্যাপ্লিকেশনকে তার RemoteNotification ট্রাফিকের ২৫% পর্যন্ত দমন করার অনুমতি দেওয়া হয়। কোনও অ্যাপ্লিকেশনের সাপ্রেশন রেট ২৫% ছাড়িয়ে গেলে, GMS Core অটোমেটিক remote_notification.notification পেলোড থেকে রেন্ডার করা ফলব্যাক বিজ্ঞপ্তি রেন্ডার ও পোস্ট করে।

অ্যাপ্লিকেশনটি ফোরগ্রাউন্ডে অ্যাক্টিভ থাকাকালীন পারফর্ম করা সাপ্রেশন এই থ্রেশহোল্ডে গণনা করা হয় না। যেসব অ্যাপ্লিকেশনকে ব্যাকগ্রাউন্ডে অবাধে ব্যবহারের অনুমতি দেওয়া হয়েছে, সেগুলির ক্ষেত্রে ব্যাকগ্রাউন্ডে ব্যবহারের সীমা প্রযোজ্য নয়।