React-native-firebase messaging not working for Android 13 device in published app (but works in debug mode)

810 views Asked by At

I am facing some issues with implementing react-native firebase messaging notification. I have used firebase-message(v6, which is the latest one I believe) and Notifee(for local notification) So, a message is sent from the backend server and received by a device using firebase messaging. It works in debug mode for Android 13 devices, but not in release mode(published app in play store)

At first, I thought it was the signing key which will create different results between the debug app and the released app, but it turns out that in Android 9 device, the app works in both types of app.

So, I am thinking that it's somethig to do with Android 13 device.

Yet, the push notification works in debug mode(even for Android 13), which makes me confused again.. I have added the POST_NOTIFICATIONS and implemented the asking permission as well. All works in debug and release, but not for ANDROID 13 combined with the released app.

Does anyone have an idea of what might be causing this result..? Below is the chart I drew for explanation...

Firebase messaging working or not

react-nativeversion: 0.71.0

Here is the code.

  1. part of app/build.gradle
dependencies {
    //minsoura
    // implementation "com.facebook.react:react-native:+"  // From node_modules

    implementation("com.facebook.react:react-android")
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

    implementation project(':react-native-vector-icons')

    //firebase
    implementation platform('com.google.firebase:firebase-bom:32.1.0')
    // Add the dependencies for the Firebase Cloud Messaging and Analytics libraries
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-messaging'
    implementation 'com.google.firebase:firebase-analytics'

    implementation 'com.facebook.fresco:animated-gif:2.5.0'


    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }
    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") 

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }
}



apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply plugin: 'com.google.gms.google-services'
  1. part of project/build.gradle

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33 // Change this line
        targetSdkVersion = 33 // Also update the targetSdkVersion to 33
        kotlinVersion = "1.6.20"
        googlePlayServicesAuthVersion = "19.2.0" 
        ndkVersion = "23.1.7779620"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {

        classpath("com.android.tools.build:gradle:7.3.1") //conversion
        classpath("com.facebook.react:react-native-gradle-plugin")

        classpath 'com.google.gms:google-services:4.3.14'

        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" // may not be working added 2023 04 13
        // classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" //conversion
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

  1. part of Android Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

    <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" /> 
    <uses-permission android:name="android.permission.VIBRATE" />

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

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/tagmeet_icon"
      android:roundIcon="@mipmap/tagmeet_icon"
      android:allowBackup="true"
      android:usesCleartextTraffic="true"
      android:exported="true"
      android:theme="@style/AppTheme">

      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:exported="true"
        android:windowSoftInputMode="adjustResize">
        <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

        <meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="foreground" />
        
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      <intent-filter android:label="filter_react_native">
        <data android:scheme="tagmeet" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
       
      </intent-filter>

      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

</manifest>

  1. App.js ( react- native) partial code
import AppNavigator from './src/AppNavigator';
import React, {useState, useEffect, useRef} from 'react';
import {NavigationContainer} from '@react-navigation/native';
import {Linking,LogBox, PermissionsAndroid, Alert} from 'react-native';
import {SheetProvider} from "react-native-actions-sheet";
import SplashScreen from 'react-native-splash-screen';
import messaging from '@react-native-firebase/messaging'

import { navigationRef, navigate } from './RootNavigation';
import { requestUserPermission, notificationListener, updateSimpleNotiCheckAndNavigate } from './FirebaseMessagingRouter';

import { AppState } from 'react-native';
import notifee, {EventType} from '@notifee/react-native';
import axios from 'axios';



function App() {

  const DefaultReuqestPermisson = async()=>{
    try {
      console.log('[Android Permission] Requesting Permission...!!!')
      await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS); 
    }catch (error) { 
      console.log('RequestPermission Error', error)
    }
  }

  const requestUserPermission = async () => {

    const authStatus = await messaging().requestPermission();
    const enabled =
      authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
      authStatus === messaging.AuthorizationStatus.PROVISIONAL;
      
    console.log("[Firebase requestUserPermission ]:", authStatus)

  };



  useEffect(() => {
    
    console.log("[App] Starting App..",)
    //request permission
    DefaultReuqestPermisson()
    requestUserPermission();

    //check if a message is recevied..
    const FBUnsubscribe = messaging().onMessage(async remoteMessage => {
      Alert.alert('A new FCM message arrived [App Section] !', JSON.stringify(remoteMessage));
      console.log("[FIREBAESE] A new FCM message arrived.. ")
    });

   
  }, []);


  return (
        <NavigationContainer ref = {navigationRef} >
          <SheetProvider>
            {<AppNavigator />}
          </SheetProvider>
        </NavigationContainer>
    
  )

}

export default App;
0

There are 0 answers