在后台处理FCM通知 - Android

时间:2016-06-20 21:58:32

标签: android notifications firebase firebase-cloud-messaging

Hello其他程序员,我目前正在使用Firebase的FCM开发一个Android应用程序,我现在能够在应用程序处于前台时处理通知但是当它在后台时它只启动活动我想用通知的数据来做这些事情,我已经阅读了docs并且它说我必须使用action_click并且数据将在我的活动中作为额外内容但是这不会发生,所以,任何你们有一个线索,如何在背景上的应用程序获得通知nada?

这是我的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>

我目前正在使用firebase指南给出的两个类:

这就是我在MainActivity中创建信息的方法:

        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..
            }
        }
    }

正如我所说,当应用程序位于前台时,我可以使用通知中的信息,但当应用程序在后台时,它只会启动我的主动,并且额外内容为空,我真的很感激,如果你伙计们可以帮我这个,抱歉我的英文不好,谢谢。

修改

这是我通过firebase从服务器获取的文本

From firebase console

0 个答案:

没有答案