Push notification issue if the app is closed

I am manage to make the push notification from backendless console works by follow the link below:

However, the device is not able to receive push notification if the app closed. Cloud anyone please advise on this?

Hello, @CHEONG_YEW_HOONG.
This problem exists on both platform(Android & iOS)?

Best Regards, Nikita.

@Nikita_Fedorishchev

Hi Nikita,

Nope. currently only testing using android devices.

Your AndroidManifest must contains:

   <service android:name="com.backendless.backendless_sdk.common.FlutterBackendlessFCMService"
       android:exported="true">
       <intent-filter>
           <action android:name="com.google.firebase.MESSAGING_EVENT" />
       </intent-filter>
   </service>

and this:

    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
    <uses-permission android:name="android.permission.BACKGROUND_SERVICE"/>

Additionaly, your build.gradle dependencies must look like this:

dependencies {
    implementation 'com.android.support:multidex:1.0.3'
    implementation platform('com.google.firebase:firebase-bom:29.0.0')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-core:20.0.0'
    implementation 'com.google.firebase:firebase-messaging:23.0.0'
    implementation 'com.google.firebase:firebase-iid'
}

Make sure your application has the above annotations.

Best Regards, Nikita.

@Nikita_Fedorishchev

Hi Nikita,

Thanks for the advise. But still i can only receive push notification while the app is open/running. Additionally i found there was a error processing warning at my flutter console:

D/FLTFireMsgReceiver(19089): broadcast received for message
W/ch.gaugetestin(19089): Accessing hidden method Landroid/os/WorkSource;->add(I)Z (unsupported,test-api, reflection, allowed)
W/ch.gaugetestin(19089): Accessing hidden method Landroid/os/WorkSource;->add(ILjava/lang/String;)Z (unsupported,test-api, reflection, allowed)
W/ch.gaugetestin(19089): Accessing hidden method Landroid/os/WorkSource;->get(I)I (unsupported, reflection, allowed)
W/ch.gaugetestin(19089): Accessing hidden method Landroid/os/WorkSource;->getName(I)Ljava/lang/String; (unsupported, reflection, allowed)
E/BackendlessFCMService(19089): Error processing push notification
E/BackendlessFCMService(19089): java.lang.IllegalArgumentException: com.exceltech.gaugetesting: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
E/BackendlessFCMService(19089): Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
E/BackendlessFCMService(19089): at android.app.PendingIntent.checkFlags(PendingIntent.java:382)
E/BackendlessFCMService(19089): at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:465)
E/BackendlessFCMService(19089): at android.app.PendingIntent.getActivity(PendingIntent.java:451)
E/BackendlessFCMService(19089): at android.app.PendingIntent.getActivity(PendingIntent.java:415)
E/BackendlessFCMService(19089): at com.backendless.push.PushTemplateHelper.convertFromTemplate(PushTemplateHelper.java:267)
E/BackendlessFCMService(19089): at com.backendless.push.BackendlessFCMService.handleMessageWithTemplate(BackendlessFCMService.java:134)
E/BackendlessFCMService(19089): at com.backendless.push.BackendlessFCMService.handleMessage(BackendlessFCMService.java:102)
E/BackendlessFCMService(19089): at com.backendless.push.BackendlessFCMService.onMessageReceived(BackendlessFCMService.java:68)
E/BackendlessFCMService(19089): at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(FirebaseMessagingService.java:235)
E/BackendlessFCMService(19089): at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(FirebaseMessagingService.java:185)
E/BackendlessFCMService(19089): at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(FirebaseMessagingService.java:172)
E/BackendlessFCMService(19089): at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(FirebaseMessagingService.java:161)
E/BackendlessFCMService(19089): at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$com-google-firebase-messaging-EnhancedIntentService(EnhancedIntentService.java:78)
E/BackendlessFCMService(19089): at com.google.firebase.messaging.EnhancedIntentService$$ExternalSyntheticLambda1.run(Unknown Source:6)
E/BackendlessFCMService(19089): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/BackendlessFCMService(19089): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/BackendlessFCMService(19089): at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@18.1.0:2)
E/BackendlessFCMService(19089): at java.lang.Thread.run(Thread.java:920)

Can you share with me your android manifest and build gradle files?

Below my manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="XXXXXXXXXX">
   <application
        android:label="XXXXXXXXXX"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:icon="@mipmap/ic_launcher"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- 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. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
        <meta-data android:name="com.google.android.geo.API_KEY"
            android:value="XXXXXXXXXX"/>
        <service android:name="com.backendless.backendless_sdk.common.FlutterBackendlessFCMService"
                  android:exported="true">
          <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
          </intent-filter>
        </service>

    </application>
         <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
    <uses-permission android:name="android.permission.BACKGROUND_SERVICE"/>   
</manifest>

Below my build.gradle:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

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: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
   def keystorePropertiesFile = rootProject.file('key.properties')
   if (keystorePropertiesFile.exists()) {
       keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
   }

   android {
    //compileSdkVersion flutter.compileSdkVersion
    compileSdkVersion 33

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "XXXXXXXXXX"
        minSdkVersion 21
        targetSdkVersion 31
        versionCode flutterVersionCode.toInteger()
        //versionCode 2
        versionName flutterVersionName
    }

   signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }
   buildTypes {
       release {
           signingConfig signingConfigs.release
       }
   }

}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.android.gms:play-services-auth:20.1.0'
    
    
    implementation 'com.android.support:multidex:1.0.3'
    implementation platform('com.google.firebase:firebase-bom:29.0.0')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-core:20.0.0'
    implementation 'com.google.firebase:firebase-messaging:23.0.8'
    implementation 'com.google.firebase:firebase-iid'

    //implementation("com.google.firebase:firebase-iid")
    implementation 'androidx.work:work-runtime-ktx:2.8.0-alpha01'
    implementation group: 'com.backendless', name: 'backendless', version: '6.3.5'  
    // required for real-time database and real-time messaging  
    implementation ('io.socket:socket.io-client:1.0.0') {  
    // excluding org.json which is provided by Android  
    exclude group: 'org.json', module: 'json'  
    } 
}

Hello, your files look correct.

Could you clarify what your push notification priority is. Also, please specify in the background fashion, they do not come at all, or do they come only to the tray?

Best Regards, Nikita.

Hi Nikita,

The setting of the priority is max. If the app is closed, the push notification doesn’t come at all.

Delete the app completely and reinstall it. Make sure the app is asking for “permissions to send push notifications”.
Additionaly, are you use the latest version of backendless_sdk.

Hi Nikita,

Yes, the backendless sdk version is 7.2.5 which the the latest. I have deleted the app and install it again but the outcome is still the same. Anyway, the device didn’t ask for “permissions to send push notifications” after the installation. Not sure what is the issue.

Hello, @CHEONG_YEW_HOONG.

I assume that this is the problem. Try requesting permissions to send push notifications. For example, using the library permission_handler | Flutter Package.

Best Regards, Nikita.