Hello fellow programmers, I am currently developing an Android application usingn Firebase's FCM, I am currently able to to handle the notifications when the app is in foreground but when it is on the background it only launches the activity where I want to do the things with the notifications's data, I have read the docs and it says thatr i must use action_click and the data will be in my activity as extras but this doesnt happen, so, any of you guys have a clue of how to get the notification nada when the apps on background?
This is my Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Enrola"
android:screenOrientation="portrait"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="OPEN_ACTIVITY_1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="OPEN_ACTIVITY_2" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".LogInActivity"
android:theme="@style/AppThemeLOGIN" />
<activity android:name=".LauncherActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".utils.MyFirebaseInstanceIDService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".utils.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
I am currently using two classes given by firebase guidelines:
And this is how i catch the information in my MainActivity's onCreate:
if (getIntent().getExtras() != null) {
String extraid = getIntent().getExtras().getString("id");
String extraclick_Action = getIntent().getExtras().getString("click_action");
Toast.makeText(MainActivity.this, "id " + extraid + " click_action " + extraclick_Action, Toast.LENGTH_LONG).show();
if (extraclick_Action != null) {
if (extraclick_Action.equals("OPEN_ACTIVITY_1")) {
//code using the id from intent
} else {
//more code..
}
}
}
As I said, i am able to use the information from the notification when the app is in the foreground but when the app is in the background it only launches my mainactivity, and the extras are null, i would really appreciate if you guys could help me with this, sorry for my bad english, thank you.
EDIT
This is the text i get from my server through firebase