How to fix Background Android Notifications for Cordova apps
I’ve been banging my head against the wall for background Android notifications for a longtime. They just were not re-opening the app, when tapped. I’m using cordova-plugin-firebasex.
To get them to work, you need to edit AndroidManifest.xml and change this line
<activity android:excludeFromRecents="true" android:exported="true" android:name="org.apache.cordova.firebase.OnNotificationReceiverActivity" android:noHistory="true" android:taskAffinity="" android:theme="@android:style/Theme.Translucent.NoTitleBar"/> To this….
<activity android:excludeFromRecents="true" android:exported="true" android:name="org.apache.cordova.firebase.OnNotificationReceiverActivity" android:noHistory="true" android:taskAffinity="" android:theme="@android:style/Theme.Translucent.NoTitleBar"> <intent-filter> <action android:name="MYCLICKACTIVITY" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> You also need ‘click_action’:’MYCLICKACTIVITY’ in the android > notification json sent to Firebase!
Don’t do a Cordova Build Android, because it will change it back!
I’ve founded it quicker to only do a cordova build when changing plugins etc. Otherwise it’s quicker to copy and past the JS or CSS files in Android Studio.