Cordova plugin firebasex not firing callback on Android 12 & 13

1.5k views Asked by At

I have a cordova application using cordova-plugin-firebasex to manage push notifications on mobile.

I have the following implementation to check about notification permissions, grant permissions and save FCM tokens. It works fine for IOS devices and Android devices prior of Android 12.

checkNotificationPermissions = (requested) => {
        console.log("check permissions");
        window.FirebasePlugin.hasPermission(function(hasPermission) {
            console.log("has permission: " + hasPermission);  
            if (hasPermission) {
                console.log("Remote notifications permission granted");
                // Granted
                window.FirebasePlugin.getToken(function(token){
                    console.log("Got FCM token: " + token)
                }, function(error) {
                    console.log("Failed to get FCM token", error);
                });
            } else if (!requested) {
                // Request permission
                console.log("Requesting remote notifications permission");
                window.FirebasePlugin.grantPermission(function(hasPermission){
                    console.log("Permission was " + (hasPermission ? "granted" : "denied"));
                });
            } else {
                // Denied
                console.log("Notifications won't be shown as permission is denied");
            }
        })
        window.FirebasePlugin.onMessageReceived(function(message){
            if(message && message.url){
                history.push(message.url)
            }
        }, function(error){
            console.log("Error on message received " + error);
        })
    }

The checkNotificationPermissions is properly called and window.FirebasePlugin is properly initialized (object exist if I console.log it at the top of the function). However, when running on a Android 13 physical device, code never seems to reach window.FirebasePlugin.hasPermission callback (neither success nor error).

I've already added POST_NOTIFICATIONS permission in my config.xml according to new Android 13 requirements:

<config-file target="AndroidManifest.xml" parent="/*">
   <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
</config-file>

I'm running on

  • cordova 12.0.0 (cordova-ios 6.3.0 & cordova-android 12.0.0)
  • cordova-plugin-firebasex 16.1.0
  • cordova-plugin-statusbar 3.0.0
  • Samsung Galaxy A33 with Android 13

Any idea ? Thanks for your help.

EDIT I found this log in the logcat when running on Android 12 & 13 suggesting exec() function is constantly ignored. Can't figure out why though...

CordovaBridge: Ignoring exec() from previous page load.

Should display the following logs:

  • check permissions
  • has permission: false
  • Requesting remote notifications permission
  • Permission was granted

Logs I get:

  • check permissions
1

There are 1 answers

0
Chouffiboy On BEST ANSWER

I end up finding the source of the error and the solution.

The ignoring exec() error:

CordovaBridge: Ignoring exec() from previous page load.

originated from another error:

CordovaBridge: gap_init called from restricted origin: http://localhost/

According to this post https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/600#issuecomment-771246329, I had to make sure I whitelisted my hostname and scheme. I already did it for the scheme but adding the hostname in my config.xml solved the problem.

<preference name="Hostname" value="localhost" />