'Extra Intent data getting null when application in background for FCM
Details:
- Android device: Nexus 5 or emulator
- Android OS version: Android N or Android M
- Google Play Services version: 9.2.1
- Firebase/Play Services SDK version: 9.2.1
Observed Results:
Though the notification does appear in the system tray, the data is NOT available in the intent. Either in onNewIntent or in onCreate, the extras is null.
Expected Results:
According to the Firebase Cloud Messaging docs, when the App State is in background and a Notification with data is sent, the notification appears in the system tray and the data will be available in the extras of the intent.
@Override
public void onCreate() {
Bundle extras = getintent().getExtras();
---> extras is always null when app is not running or when app is in background
}
or
@Override
public void onNewIntent(Intent intent) {
Bundle extras = intent.getExtras();
---> extras is always null when app is not running or when app is in background
}
Remarks: The data is available when App State is in the Foreground. But the notification console is pretty much unusable with this bug because ALL (background, app not running, foreground) users need to be able to get the data in a notification. Otherwise, how does a developer know what data a user saw or didn't see (e.g. whether a user was shown the discount 10% or not).
Solution 1:[1]
You have to set the default category tag for your launcher activity by adding this line in the AndroidManifest.xml:
<category android:name="android.intent.category.DEFAULT" />
like this:
<activity
android:name=".ui.splash.SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
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 | Ali |
