'Flutter Firebase Messaging cannot click on notification
When I receive notification using firebase_messaging, be it directly from firebase, or using my backend server through firebase with FCM tokens, I cannot click on the notification to open the app.
This is only the issue when I am outside the app, I get the notification, but cannot click on it, also in debug terminal I get:
[ +118 ms] W/FirebaseMessaging( 8761): Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
[ +24 ms] I/flutter ( 8761): Handling a background message 0:1645607606472998%5807eab55807eab5
[ +10 ms] W/FirebaseMessaging( 8761): No activity found to launch app
[ ] I/flutter ( 8761): message also contained a notification: Instance of 'RemoteNotification'
If I am inside the app, I get the notification and I can handle it however I want. For example I can use local notification to then parse the push notification and create new notification locally. If done this way, I can leave the app and click on that notification and it will take me back into the app.
I only have issue with notification when I am outside the app.
This is my android manifest file:
package="com.example.zira_mobile">
<application
android:label="@string/app_name"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTask"
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"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="ziramob.page.link" android:scheme="https"/>
<data android:host="ziramobile.page.link" android:scheme="https"/>
</intent-filter>
<!-- Add below to ensure we get the payload when tapping on a notification -->
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</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" />
</application>
</manifest>
I am using android flavors (followed this guide, and I am suspecting that something is conflicting because of that, but I am unsure).
I have tried googling, but most solutions are either directly for android, Kotlin, or Flutter embedding v1, and I am using v2, which is supposed to be no hassle and immediately working.
Solution 1:[1]
It seems the issue was the following part of the above manifest file:
<data android:host="ziramob.page.link" android:scheme="https"/>
<data android:host="ziramobile.page.link" android:scheme="https"/>
For some reason deeplinking causes issues with notifications and makes firebase messaging service not recognize what app to open on notification click.
If somebody knows whats going on and how to make both work together, please do, until then, notifications arem ore important then one click sign in.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | xcyteh |
