เริ่มต้นใช้งาน Firebase Cloud Messaging ในแอป Android

เลือกแพลตฟอร์ม: iOS+ Android Web Flutter Unity C++


คู่มือนี้อธิบายวิธีเริ่มต้นใช้งาน Firebase Cloud Messaging ในแอปไคลเอ็นต์ Android เพื่อให้คุณส่งข้อความได้อย่างน่าเชื่อถือ

FCM ไคลเอ็นต์ต้องใช้อุปกรณ์ที่ใช้ Android 6.0 หรือ สูงกว่าซึ่งติดตั้งแอป Google Play Store หรือโปรแกรมจำลอง ที่ใช้ Android 6.0 พร้อม Google API โปรดทราบว่าคุณสามารถเลือกที่จะไม่ติดตั้งใช้งานแอป Android ผ่าน Google Play Store ก็ได้

ตั้งค่า SDK

เพิ่ม Firebase ลงในโปรเจ็กต์ Android หากยังไม่ได้เพิ่ม

เราขอแนะนำให้เปิดใช้ Google Analyticsใน โปรเจ็กต์เพื่อให้ได้รับประสบการณ์การใช้งานFCMที่ดีที่สุด Google Analytics เป็นข้อกำหนดสำหรับการรายงานการส่งข้อความ ของ FCM

แก้ไขไฟล์ Manifest ของแอป

เพิ่มข้อมูลต่อไปนี้ลงในไฟล์ Manifest ของแอป

ขอสิทธิ์การแจ้งเตือนรันไทม์ใน Android 13 ขึ้นไป

Android 13 ขอแนะนำสิทธิ์รันไทม์ใหม่สำหรับการแสดงการแจ้งเตือน ซึ่งจะส่งผลต่อแอปทั้งหมดที่ทำงานบน Android 13 ขึ้นไปซึ่งใช้FCM การแจ้งเตือน

โดยค่าเริ่มต้น FCM SDK (เวอร์ชัน 23.0.6 ขึ้นไป) จะรวมสิทธิ์ POST_NOTIFICATIONS ที่กำหนดไว้ในไฟล์ Manifest อย่างไรก็ตาม แอปของคุณจะต้องขอสิทธิ์เวอร์ชันรันไทม์นี้ด้วยโดยใช้ค่าคงที่ android.permission.POST_NOTIFICATIONS แอปของคุณจะแสดงการแจ้งเตือนไม่ได้จนกว่าผู้ใช้จะให้สิทธิ์นี้

วิธีขอสิทธิ์รันไทม์ใหม่

Kotlin

// Declare the launcher at the top of your Activity/Fragment:
private val requestPermissionLauncher = registerForActivityResult(
    ActivityResultContracts.RequestPermission(),
) { isGranted: Boolean ->
    if (isGranted) {
        // FCM SDK (and your app) can post notifications.
    } else {
        // TODO: Inform user that that your app will not show notifications.
    }
}

private fun askNotificationPermission() {
    // This is only necessary for API level >= 33 (TIRAMISU)
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) ==
            PackageManager.PERMISSION_GRANTED
        ) {
            // FCM SDK (and your app) can post notifications.
        } else if (shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) {
            // TODO: display an educational UI explaining to the user the features that will be enabled
            //       by them granting the POST_NOTIFICATION permission. This UI should provide the user
            //       "OK" and "No thanks" buttons. If the user selects "OK," directly request the permission.
            //       If the user selects "No thanks," allow the user to continue without notifications.
        } else {
            // Directly ask for the permission
            requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
        }
    }
}

Java

// Declare the launcher at the top of your Activity/Fragment:
private final ActivityResultLauncher<String> requestPermissionLauncher =
        registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
            if (isGranted) {
                // FCM SDK (and your app) can post notifications.
            } else {
                // TODO: Inform user that that your app will not show notifications.
            }
        });

private void askNotificationPermission() {
    // This is only necessary for API level >= 33 (TIRAMISU)
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) ==
                PackageManager.PERMISSION_GRANTED) {
            // FCM SDK (and your app) can post notifications.
        } else if (shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) {
            // TODO: display an educational UI explaining to the user the features that will be enabled
            //       by them granting the POST_NOTIFICATION permission. This UI should provide the user
            //       "OK" and "No thanks" buttons. If the user selects "OK," directly request the permission.
            //       If the user selects "No thanks," allow the user to continue without notifications.
        } else {
            // Directly ask for the permission
            requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS);
        }
    }
}

โดยทั่วไป คุณควรแสดง UI ที่อธิบายให้ผู้ใช้ทราบถึงฟีเจอร์ที่จะเปิดใช้หากผู้ใช้ให้สิทธิ์แอปในการโพสต์การแจ้งเตือน UI นี้ควรมีตัวเลือกให้ผู้ใช้ยอมรับหรือปฏิเสธ เช่น ปุ่มตกลง และปุ่มไม่เป็นไร หากผู้ใช้เลือกตกลง ให้ขอสิทธิ์โดยตรง หากผู้ใช้เลือกไม่เป็นไร ให้ผู้ใช้ดำเนินการต่อโดยไม่รับ การแจ้งเตือน

ดูแนวทางปฏิบัติแนะนำเพิ่มเติมเกี่ยวกับเวลาที่แอปควรขอสิทธิ์ POST_NOTIFICATIONS จากผู้ใช้ได้ที่สิทธิ์รันไทม์ของการแจ้งเตือน

สิทธิ์การแจ้งเตือนสำหรับแอปที่กำหนดเป้าหมายเป็น Android 12L (ระดับ API 32) หรือต่ำกว่า

Android จะขอสิทธิ์จากผู้ใช้โดยอัตโนมัติในครั้งแรกที่แอปสร้างช่องทางการแจ้งเตือน ตราบใดที่แอปทำงานอยู่เบื้องหน้า อย่างไรก็ตาม มีข้อควรระวังที่สำคัญเกี่ยวกับเวลาในการสร้างช่องทางและการขอสิทธิ์ดังนี้

  • หากแอปสร้างช่องทางการแจ้งเตือนช่องทางแรกเมื่อแอปทำงานใน เบื้องหลัง ซึ่ง FCM SDK จะทำเช่นนั้นเมื่อได้รับการแจ้งเตือน FCM Android จะไม่อนุญาตให้แสดงการแจ้งเตือนและจะไม่ แจ้งให้ผู้ใช้ขอสิทธิ์การแจ้งเตือนจนกว่าจะมีการเปิดแอป ครั้งถัดไป ซึ่งหมายความว่าการแจ้งเตือนที่ได้รับก่อนที่จะมีการเปิดแอปและผู้ใช้ยอมรับสิทธิ์จะสูญหาย
  • เราขอแนะนำอย่างยิ่งให้อัปเดตแอปให้กำหนดเป้าหมายเป็น Android 13 ขึ้นไปเพื่อใช้ประโยชน์จาก API ของแพลตฟอร์มในการขอสิทธิ์ หากทำไม่ได้ แอปควรสร้างช่องทางการแจ้งเตือนก่อนที่จะส่งการแจ้งเตือนไปยังแอปเพื่อทริกเกอร์กล่องโต้ตอบสิทธิ์การแจ้งเตือนและตรวจสอบว่าไม่มีการแจ้งเตือนสูญหาย ดูข้อมูลเพิ่มเติมได้ที่แนวทางปฏิบัติแนะนำเกี่ยวกับสิทธิ์การแจ้งเตือน สำหรับ ข้อมูลเพิ่มเติม

ไม่บังคับ: นำสิทธิ์ POST_NOTIFICATIONS ออก

โดยค่าเริ่มต้น FCM SDK จะรวมสิทธิ์ POST_NOTIFICATIONS หากแอปไม่ได้ใช้ข้อความแจ้งเตือน (ไม่ว่าจะผ่านFCM การแจ้งเตือน, ผ่าน SDK อื่น หรือโพสต์โดยแอปของคุณโดยตรง) และคุณ ไม่ต้องการให้แอปมีสิทธิ์ดังกล่าว คุณสามารถนำสิทธิ์ออกได้โดยใช้เครื่องหมาย ของเครื่องมือผสานไฟล์ Manifest remove โปรดทราบว่าการนำสิทธิ์นี้ออกจะป้องกันไม่ให้แสดงการแจ้งเตือนทั้งหมด ไม่ใช่แค่การแจ้งเตือน FCM เพิ่มข้อมูลต่อไปนี้ลงในไฟล์ Manifest ของแอป

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" tools:node="remove"/>

เข้าถึงรหัสการติดตั้ง Firebase

เมื่อเริ่มต้นแอปครั้งแรก FCM SDK จะลงทะเบียนอินสแตนซ์ของแอปกับ FCM และแสดงตัวระบุสำหรับอินสแตนซ์ของแอป หากต้องการกำหนดเป้าหมายเป็นอินสแตนซ์ของแอปแต่ละรายการ คุณจะต้องเข้าถึงตัวระบุนี้โดยขยาย FirebaseMessagingService และลบล้าง onRegistered() แนวทางปฏิบัติแนะนำคือให้ดึงข้อมูลตัวระบุที่อัปเดตล่าสุดเนื่องจากตัวระบุอาจมีการหมุนเวียนหลังจากเริ่มต้นครั้งแรก

เปิดใช้การลงทะเบียนผ่านรหัสการติดตั้ง Firebase

หากต้องการเปิดใช้การลงทะเบียนอินสแตนซ์ของแอปกับ FCM โดยใช้ รหัสการติดตั้ง Firebase (FID), ให้เพิ่มแฟล็กข้อมูลเมตาต่อไปนี้ลงในไฟล์ AndroidManifest.xml
<meta-data
    android:name="firebase_messaging_installation_id_enabled"
    android:value="true" />

ใช้การเรียกกลับ onRegistered()

ระบบจะกำหนดเป้าหมายเป็นอินสแตนซ์ของแอปโดยใช้รหัสการติดตั้ง Firebase (FID) เมื่อลงทะเบียน กับ FCM แล้ว หากต้องการดึงข้อมูล FID เมื่อลงทะเบียน ให้ใช้การเรียกกลับ onRegistered() เมื่ออินสแตนซ์ของแอปได้รับการลงทะเบียนแล้ว FCM SDK จะตรวจสอบการเปลี่ยนแปลง FID โดยอัตโนมัติและเรียกใช้การเรียกกลับเมื่อตรวจพบการเปลี่ยนแปลง เมื่อเปิดใช้การเริ่มต้นอัตโนมัติ FCM SDK จะซิงค์กับแบ็กเอนด์ FCM โดยอัตโนมัติเพื่อให้การลงทะเบียนเป็นปัจจุบันอยู่เสมอ และเรียกใช้การเรียกกลับ เพื่อให้แน่ใจว่าเซิร์ฟเวอร์แอปมีตัวระบุปัจจุบัน คุณควรส่ง FID ไปยังเซิร์ฟเวอร์แอปทุกครั้งที่การเรียกกลับนี้ทริกเกอร์เพื่อป้องกันไม่ให้ FID สูญหายหรือ ล้าสมัย

Kotlin

  /**
   * There are three scenarios when `onRegistered` is called:
   * 1) Every time a manual `register()` call finishes successfully
   * 2) Whenever the FID is changed and the app is re-registered with FCM via the new FID.
   * 3) Automatically on app startup or routine sync when auto-initialization is enabled.
   * Under #2, there are three scenarios when the existing FID is changed:
   * A) App is restored to a new device
   * B) User uninstalls/reinstalls the app
   * C) User clears app data
   */
  override fun onRegistered(installationId: String) {
      Log.d(TAG, "Registered installation ID: $installationId")

      // Send the Firebase Installation ID to your app server.
      sendRegistrationToServer(installationId)
  }
    

Java

  /**
   * There are three scenarios when `onRegistered` is called:
   * 1) Every time a manual `register()` call finishes successfully
   * 2) Whenever the FID is changed and the app is re-registered with FCM via the new FID
   * 3) Automatically on app startup or routine sync when auto-initialization is enabled.
   * Under #2, there are three scenarios when the existing FID is changed:
   * A) App is restored to a new device
   * B) User uninstalls/reinstalls the app
   * C) User clears app data
   */
  @Override
  public void onRegistered(@NonNull String installationId) {
      Log.d(TAG, "Registered installation ID: " + installationId);

      // Send the Firebase Installation ID to your app server.
      sendRegistrationToServer(installationId);
  }
    

ลงทะเบียนด้วยตนเองเมื่อปิดใช้การเริ่มต้นอัตโนมัติ

หากคุณต้องปิดใช้การเริ่มต้นอัตโนมัติ FCM SDK จะไม่ซิงค์หรือทริกเกอร์การเรียกกลับเมื่อเริ่มต้นonRegistered() เราขอแนะนำอย่างยิ่งให้เปิดใช้การเริ่มต้นอัตโนมัติอีกครั้งหลังจาก ได้รับสิทธิ์การแจ้งเตือน ดูข้อมูลเพิ่มเติมได้ที่ เปิดใช้การเริ่มต้นอัตโนมัติอีกครั้ง

หากต้องปิดใช้การเริ่มต้นอัตโนมัติต่อไป ให้เรียกใช้ FirebaseMessaging.getInstance().register() เมื่อเริ่มต้นแอปเพื่อทริกเกอร์ การลงทะเบียนและการส่ง FID ผ่านการเรียกกลับ onRegistered() คุณสามารถ เรียกใช้การเรียกนี้ได้ภายใน onCreate() เมธอดของ Activity หลัก

Kotlin

  // Trigger manual registration if auto-initialization is turned off.
  // Consider calling this every time the app starts to guarantee sync status.
  FirebaseMessaging.getInstance().register()
      .addOnCompleteListener(this) { task ->
        if (!task.isSuccessful()) {
          // Registration failed. Consider retrying the registration with exponential backoff.
          Log.w(TAG, "Failed to register with Firebase Cloud Messaging", task.exception)
        }
        // Success! The Firebase Installation ID can be used to target messages to this app
        // instance and will be delivered asynchronously to your `onRegistered()` callback.
      }
    

Java

  // Trigger manual registration if auto-initialization is turned off.
  // Consider calling this every time the app starts to guarantee sync status.
  FirebaseMessaging.getInstance().register()
      .addOnCompleteListener(task -> {
        if (!task.isSuccessful()) {
          // Registration failed. Consider retrying the registration with exponential backoff.
          Log.w(TAG, "Failed to register with Firebase Cloud Messaging", task.exception)
        }
        // Success! The Firebase Installation ID can be used to target messages to this app
        // instance and will be delivered asynchronously to your `onRegistered()` callback.
      });
    

เข้าถึงโทเค็นการลงทะเบียน FCM (เลิกใช้งานแล้ว)

ได้ที่แนวทางปฏิบัติแนะนำสำหรับการจัดการการลงทะเบียน FCM

เมื่อเริ่มต้นแอปครั้งแรก FCM SDK จะสร้างโทเค็นการลงทะเบียน สำหรับอินสแตนซ์ของแอปไคลเอ็นต์ หากต้องการกำหนดเป้าหมายเป็นอินสแตนซ์ของแอปรายการเดียวหรือ สร้างกลุ่มอุปกรณ์ คุณจะต้องเข้าถึงโทเค็นนี้โดยขยาย FirebaseMessagingServiceและลบล้างonNewToken เนื่องจากโทเค็นอาจมีการหมุนเวียนหลังจากเริ่มต้นครั้งแรก เราจึงขอแนะนำอย่างยิ่งให้ดึงข้อมูลโทเค็นการลงทะเบียนที่อัปเดตล่าสุด

โทเค็นการลงทะเบียนอาจเปลี่ยนแปลงเมื่อเกิดเหตุการณ์ต่อไปนี้

  • มีการกู้คืนแอปในอุปกรณ์เครื่องใหม่
  • ผู้ใช้ถอนการติดตั้ง/ติดตั้งแอปอีกครั้ง
  • ผู้ใช้ล้างข้อมูลแอป

ดึงข้อมูลโทเค็นการลงทะเบียนปัจจุบัน

เมื่อต้องการดึงข้อมูลโทเค็นปัจจุบัน ให้เรียกใช้ FirebaseMessaging.getInstance().getToken()

Kotlin

FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
    if (!task.isSuccessful) {
        Log.w(TAG, "Fetching FCM registration token failed", task.exception)
        return@OnCompleteListener
    }

    // Get new FCM registration token
    val token = task.result

    // Log and toast
    val msg = getString(R.string.msg_token_fmt, token)
    Log.d(TAG, msg)
    Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show()
})

Java

FirebaseMessaging.getInstance().getToken()
    .addOnCompleteListener(new OnCompleteListener<String>() {
        @Override
        public void onComplete(@NonNull Task<String> task) {
          if (!task.isSuccessful()) {
            Log.w(TAG, "Fetching FCM registration token failed", task.getException());
            return;
          }

          // Get new FCM registration token
          String token = task.getResult();

          // Log and toast
          String msg = getString(R.string.msg_token_fmt, token);
          Log.d(TAG, msg);
          Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    });

ตรวจสอบการสร้างโทเค็น

การเรียกกลับ onNewToken จะทำงานเมื่อมีการสร้างโทเค็นใหม่

Kotlin

/**
 * Called if the FCM registration token is updated. This may occur if the security of
 * the previous token had been compromised. Note that this is called when the
 * FCM registration token is initially generated so this is where you would retrieve the token.
 */
override fun onNewToken(token: String) {
    Log.d(TAG, "Refreshed token: $token")

    // If you want to send messages to this application instance or
    // manage this apps subscriptions on the server side, send the
    // FCM registration token to your app server.
    sendRegistrationToServer(token)
}

Java

/**
 * There are two scenarios when onNewToken is called:
 * 1) When a new token is generated on initial app startup
 * 2) Whenever an existing token is changed
 * Under #2, there are three scenarios when the existing token is changed:
 * A) App is restored to a new device
 * B) User uninstalls/reinstalls the app
 * C) User clears app data
 */
@Override
public void onNewToken(@NonNull String token) {
    Log.d(TAG, "Refreshed token: " + token);

    // If you want to send messages to this application instance or
    // manage this apps subscriptions on the server side, send the
    // FCM registration token to your app server.
    sendRegistrationToServer(token);
}

หลังจากได้รับโทเค็นแล้ว คุณสามารถส่งโทเค็นไปยังเซิร์ฟเวอร์แอปและจัดเก็บ โทเค็นโดยใช้วิธีที่คุณต้องการ

ตรวจสอบบริการ Google Play

แอปที่ใช้ Play Services SDK ควรตรวจสอบอุปกรณ์เพื่อหา APK ของบริการ Google Play ที่เข้ากันได้ก่อนที่จะเข้าถึงฟีเจอร์ของบริการ Google Play เสมอ ดูข้อมูลเพิ่มเติมได้ที่ตั้งค่า Google Play บริการ เราขอแนะนำให้ดำเนินการนี้ใน 2 ที่ ได้แก่ เมธอด onCreate() ของกิจกรรมหลัก และเมธอด onResume() ของกิจกรรมหลัก การตรวจสอบใน onCreate() จะช่วยให้แน่ใจว่าแอปจะใช้งานไม่ได้หากการตรวจสอบไม่สำเร็จ การตรวจสอบใน onResume() จะช่วยให้แน่ใจว่าหากผู้ใช้กลับมาที่แอปที่กำลังทำงานอยู่ผ่านวิธีอื่น เช่น ผ่านปุ่มย้อนกลับ ระบบจะยังคงทำการตรวจสอบ

หากอุปกรณ์ไม่มีบริการ Google Play เวอร์ชันที่เข้ากันได้ แอปของคุณสามารถเรียกใช้ GoogleApiAvailability.makeGooglePlayServicesAvailable() เพื่ออนุญาตให้ผู้ใช้ดาวน์โหลดบริการ Google Play จาก Play Store ได้

ป้องกันการเริ่มต้นอัตโนมัติ

เมื่อมีการสร้างการลงทะเบียน FCM ไลบรารีจะอัปโหลดตัวระบุ และข้อมูลการกำหนดค่าไปยัง Firebase หากต้องการป้องกันการลงทะเบียนอัตโนมัติ ให้ปิดใช้การเก็บรวบรวม Analytics และการเริ่มต้นอัตโนมัติของ FCM (คุณต้องปิดใช้ทั้ง 2 อย่าง) โดยเพิ่มค่าข้อมูลเมตาต่อไปนี้ลงใน AndroidManifest.xml

<meta-data
    android:name="firebase_messaging_auto_init_enabled"
    android:value="false" />
<meta-data
    android:name="firebase_analytics_collection_enabled"
    android:value="false" />

เปิดใช้การเริ่มต้นอัตโนมัติอีกครั้ง

หากต้องการเปิดใช้การเริ่มต้นอัตโนมัติของ FCM อีกครั้ง ให้เรียกใช้รันไทม์ดังนี้

Kotlin

Firebase.messaging.isAutoInitEnabled = true

Java

FirebaseMessaging.getInstance().setAutoInitEnabled(true);

หากต้องการเปิดใช้การเก็บรวบรวม Analytics อีกครั้ง ให้เรียกใช้ setAnalyticsCollectionEnabled() เมธอดของคลาส FirebaseAnalytics เช่น

setAnalyticsCollectionEnabled(true);

ค่าเหล่านี้จะยังคงอยู่เมื่อรีสตาร์ทแอปหลังจากตั้งค่าแล้ว

ส่งข้อความแจ้งเตือน

หากต้องการตรวจสอบว่าไคลเอ็นต์ Android ได้รับการตั้งค่าอย่างถูกต้อง คุณสามารถส่งข้อความแจ้งเตือนทดสอบได้โดยใช้คำแนะนำต่อไปนี้

  1. ติดตั้งและเรียกใช้แอปในอุปกรณ์เป้าหมาย

  2. ตรวจสอบว่าแอปทำงานในเบื้องหลังในอุปกรณ์

  3. ในคอนโซลFirebase ให้ไปที่ DevOps และการมีส่วนร่วม > การรับส่งข้อความ

  4. สร้างแคมเปญ

    • หากเป็นการส่งข้อความครั้งแรก ให้ทำดังนี้

      1. เลือกสร้างแคมเปญแรก

      2. เลือกข้อความแจ้งเตือน Firebase แล้วเลือกสร้าง

    • หากคุณเคยสร้างแคมเปญไว้ก่อนหน้านี้ ให้ทำดังนี้

      1. ในแท็บแคมเปญ ให้เลือกแคมเปญใหม่

      2. คลิกการแจ้งเตือน

  5. ป้อนข้อความ ส่วนฟิลด์อื่นๆ ทั้งหมดเป็นตัวเลือก

  6. เลือกส่งข้อความทดสอบ จากแผงด้านขวา

  7. ในฟิลด์ที่มีป้ายกำกับว่าเพิ่มโทเค็นการลงทะเบียน FCM ให้ป้อน โทเค็นการลงทะเบียนที่คุณได้รับในส่วนก่อนหน้าของคู่มือนี้

  8. เลือกทดสอบ

อุปกรณ์ไคลเอ็นต์เป้าหมายที่แอปทำงานในเบื้องหลังควรได้รับการแจ้งเตือน

หากต้องการดูข้อมูลเชิงลึกเกี่ยวกับการส่งข้อความไปยังแอป ให้ไปที่แดชบอร์ด DevOps และการมีส่วนร่วม > การรับส่งข้อความ > รายงาน ในคอนโซลFirebase แดชบอร์ดนี้จะบันทึกจำนวนข้อความที่ส่งและเปิดในอุปกรณ์ Apple และ Android รวมถึงข้อมูล "การแสดงผล" (การแจ้งเตือนที่ผู้ใช้เห็น) สำหรับแอป Android

ขั้นตอนถัดไป

หลังจากทำตามขั้นตอนการตั้งค่าเสร็จแล้ว คุณสามารถเลือกตัวเลือกต่อไปนี้เพื่อดำเนินการต่อกับ FCM สำหรับ Android: