0

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

From firebase console

miguelacio
  • 152
  • 1
  • 15
  • How do you send the message? Most likely you're sending it as a notification, which means that the behavior is hard-coded to always go through the system notification center. – Frank van Puffelen Jun 20 '16 at 22:09
  • From a intent in the MyFirebaseMessagingService, i extract the data i want to get, and then i put it as extra in a Intent to my mainactivity – miguelacio Jun 20 '16 at 22:17
  • That seems to be about receiving of the message on the device. I'm specifically interested how you send the message/notification *to* the device. Are you using the Notifications panel in the Firebase Console? Or do you have code running on a server somewhere to [send a downstream message](https://firebase.google.com/docs/cloud-messaging/downstream). Can you add that code to your question by clicking the [edit](http://stackoverflow.com/posts/37932482/edit) link under it. – Frank van Puffelen Jun 20 '16 at 22:25
  • done @FrankvanPuffelen, thank you – miguelacio Jun 20 '16 at 22:40
  • You're sending a notification. When the app is not in the foreground, notifications will always be sent to the system at the moment. See [this section of the Firebase documentation](https://firebase.google.com/docs/notifications/#how_does_it_work). – Frank van Puffelen Jun 20 '16 at 23:59
  • Thats what i dont get, i updated what my server is sending me in the question, can you check it out please, i have read the docs and i seem not to get it @FrankvanPuffelen – miguelacio Jun 21 '16 at 00:11

0 Answers0