title: How to get a full screen notification from FCM?
body: <p>I am building a home automation project that has a fire sensor that will write to Firebase Database if there is a fire detected, then from that point I need to make an alarm for the user.
  I managed to trigger a notification from Firebase cloud functions, but that's not exactly what I want.
  What I want is to make a full-screen notification to the user with a custom sound something like a phone alarm or a what's app call when there is a fire alarm -change in the database-.</p>
  <p>I tried as a Top level function with no error while running my application:</p>
  <pre><code>  firebaseMessaging.configure(
        onMessage: (Map&lt;String, dynamic&gt; message) async {
          print('onMessage: $message');
          toast3('asdasdsawwwww $message');
          setMessage(message);
        },
        onLaunch: (Map&lt;String, dynamic&gt; message) async {
          print('onLaunch: $message');
          setMessage(message);
        },
        onResume: (Map&lt;String, dynamic&gt; message) async {
          print('onResume: $message');
          setMessage(message);
        },
        onBackgroundMessage: myBackgroundMessageHandler);
    print('onMessage:12qew11');
  
    firebaseMessaging.requestNotificationPermissions(
      const IosNotificationSettings(sound: true, badge: true, alert: true),
    );
  }
  
  
  Future&lt;dynamic&gt; myBackgroundMessageHandler(Map&lt;String, dynamic&gt; message) {
    print('HEREE');
   final assetsAudioPlayer = AssetsAudioPlayer();
  
      assetsAudioPlayer.open(
          Audio(&quot;assets/audio/alarm.mp3&quot;),
      );
    return Fluttertoast.showToast(
        msg: 'done background:))))$message',
        toastLength: Toast.LENGTH_LONG,
        gravity: ToastGravity.BOTTOM,
        timeInSecForIos: 4,
        backgroundColor: Colors.redAccent,
        textColor: Colors.white,
        fontSize: 15.0);
  }
  </code></pre>
  <p>My Firebase function:</p>
  <pre><code>const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  
  admin.initializeApp(functions.config().functions);
  
  var fireDatabase;
  exports.myFirstCloudFun = functions.database.ref('/usersData/{userID}/Fire').onUpdate(async (event, context) =&gt; {
  
      const uidGotten = context.params.userID;
  
      const fireData = event.after.val()
      console.log('data changed in fire is' + fireData + 'userID is ' + uidGotten);
      const usereIdTokens = await admin
          .firestore()
          .collection(uidGotten)
          .doc('userTokens')
          .get();
      console.log('Tokens to try are' + usereIdTokens.data);
  
      var tokens = usereIdTokens.data().user_all_tokens;
      var payload = {
          notification: {
              title: 'Push Title',
              body: 'Push Body' + fireData,
              sound: 'default',
          },
          data: {
              push_key: 'Fire Value Is',
              key1: &quot;fireData is &quot; + fireData,
          },
      };
      tokens.forEach.toString().trim;
  
      console.log('Tokens to send are ' + tokens[1] + '   //////   ' + tokens);
  
      try {
          const response = await admin.messaging().sendToDevice(tokens, payload);
          console.log('Notification sent successfully');
      } catch (err) {
          console.log(err);
      }
  });
  </code></pre>
  <p>My Application.kt</p>
  <pre><code>package com.eghubs.eg_home_hubs
  
  import io.flutter.app.FlutterApplication
  import io.flutter.plugin.common.PluginRegistry
  import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
  import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
  
  public class Application: FlutterApplication(), PluginRegistrantCallback {
      override fun onCreate() {
          super.onCreate()
          FlutterFirebaseMessagingService.setPluginRegistrant(this)
      }
  
      override fun registerWith(registry: PluginRegistry) {
          FirebaseCloudMessagingPluginRegistrant.registerWith(registry)
      }
  }
  </code></pre>
  <p>My FirebaseCloudMessagingPluginRegistrant.kt</p>
  <pre><code>package com.eghubs.eg_home_hubs
  
  
  import io.flutter.plugin.common.PluginRegistry
  import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin
  
  class FirebaseCloudMessagingPluginRegistrant {
      companion object {
          fun registerWith(registry: PluginRegistry) {
              if (alreadyRegisteredWith(registry)) {
                  return;
              }
              FirebaseMessagingPlugin.registerWith(registry.registrarFor(&quot;io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin&quot;))
          }
  
          fun alreadyRegisteredWith(registry: PluginRegistry): Boolean {
              val key = FirebaseCloudMessagingPluginRegistrant::class.java.name
              if (registry.hasPlugin(key)) {
                  return true
              }
              registry.registrarFor(key)
              return false
          }
      }
  }
  </code></pre>
  <p>My AndroidManifest is :</p>
  <pre><code>&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      package=&quot;com.eghubs.eg_home_hubs&quot;&gt;
      &lt;uses-permission android:name=&quot;android.permission.ACCESS_CORSE_LOCATION&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;
  
  
  
      &lt;!-- io.flutter.app.FlutterApplication is an android.app.Application that
           calls FlutterMain.startInitialization(this); in its onCreate method.
           In most cases you can leave this as-is, but you if you want to provide
           additional functionality it is fine to subclass or reimplement
           FlutterApplication and put your custom class here.
                    android:name=&quot;io.flutter.app.FlutterApplication&quot;
                    android:name=&quot;androidx.multidex.MultiDexApplication&quot;
  
  --&gt;
      &lt;application
          android:name=&quot;.Application&quot; &lt;!-- here is the change--&gt;
          android:label=&quot;EG HomeHubs&quot;
          android:allowBackup=&quot;false&quot;
          android:icon=&quot;@mipmap/ic_launcher&quot;&gt;
          tools:replace=&quot;android:allowBackup&quot;&gt;
          &lt;activity
              android:name=&quot;.MainActivity&quot;
              android:launchMode=&quot;singleTop&quot;
              android:theme=&quot;@style/LaunchTheme&quot;
              android:configChanges=&quot;orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode&quot;
              android:hardwareAccelerated=&quot;true&quot;
              android:windowSoftInputMode=&quot;adjustResize&quot;&gt;
              android:showWhenLocked=&quot;true&quot;
              android:turnScreenOn=&quot;true&quot;&gt;
              &lt;!-- Specifies an Android theme to apply to this Activity as soon as
                   the Android process has started. This theme is visible to the user
                   while the Flutter UI initializes. After that, this theme continues
                   to determine the Window background behind the Flutter UI. --&gt;
              &lt;meta-data
                android:name=&quot;io.flutter.embedding.android.NormalTheme&quot;
                android:resource=&quot;@style/NormalTheme&quot;
                /&gt;
              &lt;!-- Displays an Android View that continues showing the launch screen
                   Drawable until Flutter paints its first frame, then this splash
                   screen fades out. A splash screen is useful to avoid any visual
                   gap between the end of Android's launch screen and the painting of
                   Flutter's first frame. --&gt;
              &lt;meta-data
                android:name=&quot;io.flutter.embedding.android.SplashScreenDrawable&quot;
                android:resource=&quot;@drawable/launch_background&quot;
                /&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot;/&gt;
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot;/&gt;
              &lt;/intent-filter&gt;
              &lt;intent-filter&gt;   &lt;!-- Noti:this is for cloud messiging --&gt;
                  &lt;action android:name=&quot;FLUTTER_NOTIFICATION_CLICK&quot; /&gt;
                  &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;!-- Don't delete the meta-data below.
               This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --&gt;
          &lt;meta-data
              android:name=&quot;flutterEmbedding&quot;
              android:value=&quot;2&quot; /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  <p>but I get nothing when the application is not opened in the background, why onBackgroundMessage function is not called?</p>
  <p>My question is how can I achieve that what's an app call or something of that kind?</p>
  <p><strong>OR</strong> Is there any better way to do this, some other way to achieve that fire alarm functionality in my project from the firebase database change?</p>
  <p>EDIT: My app/build.gradle</p>
  <pre><code>def localProperties = new Properties()
  def localPropertiesFile = rootProject.file('local.properties')
  if (localPropertiesFile.exists()) {
      localPropertiesFile.withReader('UTF-8') { reader -&gt;
          localProperties.load(reader)
      }
  }
  
  def flutterRoot = localProperties.getProperty('flutter.sdk')
  if (flutterRoot == null) {
      throw new FileNotFoundException(&quot;Flutter SDK not found. Define location with flutter.sdk in the local.properties file.&quot;)
  }
  //GradleException
  
  def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
  if (flutterVersionCode == null) {
      flutterVersionCode = '1'
  }
  
  def flutterVersionName = localProperties.getProperty('flutter.versionName')
  if (flutterVersionName == null) {
      flutterVersionName = '1.0'
  }
  
  apply plugin: 'com.android.application'
  apply plugin: 'kotlin-android'
  apply from: &quot;$flutterRoot/packages/flutter_tools/gradle/flutter.gradle&quot;
  def keystoreProperties = new Properties()
  def keystorePropertiesFile = rootProject.file('key.properties')
  if (keystorePropertiesFile.exists()) {
      keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
  }
  android {
      packagingOptions {
          exclude 'META-INF/services/javax.annotation.processing.Processor'
      }
      compileSdkVersion 30
  
      sourceSets {
          main.java.srcDirs += 'src/main/kotlin'
      }
  
      lintOptions {
          disable 'InvalidPackage'
      }
  
      defaultConfig {
          // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
          applicationId &quot;com.eghubs.eg_home_hubs&quot;
          minSdkVersion 21
          targetSdkVersion 30
          versionCode flutterVersionCode.toInteger()
          versionName flutterVersionName
        //  multiDexEnabled true
  
      }
      signingConfigs {
          release {
              keyAlias keystoreProperties['keyAlias']
              keyPassword keystoreProperties['keyPassword']
              storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
              storePassword keystoreProperties['storePassword']
          }
      }
      buildTypes {
          release {
              minifyEnabled true
              shrinkResources true
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  
              // TODO: Add your own signing config for the release build.
              // Signing with the debug keys for now, so `flutter run --release` works.
              signingConfig signingConfigs.debug
          }
          debug {
              minifyEnabled true
              shrinkResources true
        }
  
      }
  }
  
  flutter {
      source '../..'
  }
  
  dependencies {
      implementation 'com.google.firebase:firebase-analytics'
      implementation platform('com.google.firebase:firebase-bom:26.0.0')
      implementation &quot;org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version&quot;
    //  implementation 'androidx.multidex:multidex:2.0.1'  //with androidx libraries
      implementation'com.google.firebase:firebase-messaging:21.0.1'
  
  
  }
  apply plugin: 'com.android.application'
  // Add this line
  apply plugin: 'com.google.gms.google-services'
  </code></pre>
  <p>My android/build.gradle:</p>
  <pre><code>buildscript {
      ext.kotlin_version = '1.3.50'
      repositories {
          google()
          jcenter()
      }
  
      dependencies {
          classpath 'com.google.gms:google-services:4.3.4'
          //classpath 'com.android.tools.build:gradle:3.5.3' //todo rollback this
          classpath 'com.android.tools.build:gradle:4.1.1'
          classpath &quot;org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version&quot;
      }
  }
  
  allprojects {
      repositories {
          google()
          jcenter()
      }
  }
  
  rootProject.buildDir = '../build'
  subprojects {
      project.buildDir = &quot;${rootProject.buildDir}/${project.name}&quot;
  }
  subprojects {
      project.evaluationDependsOn(':app')
  }
  
  task clean(type: Delete) {
      delete rootProject.buildDir
  }
  </code></pre>