Skip to main content
All Collections2. Define push_token to mobile analytics
Check Firebase Cloud Messaging SDK Implementation
Check Firebase Cloud Messaging SDK Implementation
K
Written by Kirill Slobodianiuk
Updated over a week ago

💡Sometimes there are problems with the icon not being displayed. This guide will help eliminate these problems.


Firebase Cloud Messaging SDK

  1. Make sure that you’ve implemented Firebase Cloud Messaging SDK according to this instruction.

  2. Edit your App Manifest:

    1. A service that extends FirebaseMessagingService. This is required if you want to do any message handling beyond receiving notifications on apps in the background. To receive notifications in foregrounded apps, to receive data payload, to send upstream messages, and so on, you must extend this service:

      <service 
      android:name=".java.MyFirebaseMessagingService"
      android:exported="false">
      <intent-filter>
      <action android:name="com.google.firebase.MESSAGING_EVENT" />
      </intent-filter>
      </service>
    2. Within the application component, metadata elements to set a default notification icon and color. Android uses these values whenever incoming messages do not explicitly set icon or color:

      <meta-data 
      android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_stat_ic_notification" />
      <meta-data
      android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/colorAccent" />
  3. [Optional] Request runtime notification permission on Android 13+.

    Android 13 introduces a new runtime permission for showing notifications. This affects all apps running on Android 13 or higher that use FCM notifications.

    By default, the FCM SDK (version 23.0.6 or higher) includes the [POST_NOTIFICATIONS](<https://developer.android.com/reference/android/Manifest.permission#POST_NOTIFICATIONS>) permission defined in the manifest. However, your app will also need to request the runtime version of this permission via the constant, android.permission.POST_NOTIFICATIONS. Your app will not be allowed to show notifications until the user has granted this permission.

    To request the new runtime permission:

    // 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() {
    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)
    }
    }
Did this answer your question?