GCM 无法解析目标意图服务

GCM Failed to resolve target intent service

我试图让 GCM 推送通知在我的 Android 6.0.1 设备上运行。不幸的是,我 运行 出错了。 日志说:

E/FirebaseInstanceId: Failed to resolve target intent service, skipping classname enforcement E/FirebaseInstanceId: Error while delivering the message: ServiceIntent not found.

但我没有使用 firebase。 那么为什么日志会说一些关于 firebase 的信息,为什么会发生这个错误?

我的 AndroidManifest.xml 文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.push.test">

<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.push.test.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.push.test.permission.C2D_MESSAGE" />

<application
    [...] >

    <activity android:name=".MainActivity">
        [...]
    </activity>

    <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter android:priority="1000">
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.push.test" />
        </intent-filter>
    </receiver>

    <!-- [START gcm_listener] -->
    <service
        android:name=".GcmListener"
        android:exported="false" >
        <intent-filter android:priority="1000">
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>
    <!-- [END gcm_listener] -->

    <!-- [START instanceId_listener] -->
    <service
        android:name=".InstanceListener"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.gms.iid.InstanceID"/>
        </intent-filter>
    </service>
    <!-- [END instanceId_listener] -->

    <service
        android:name=".RegistrationIntentService"
        android:exported="false">
    </service>
</application>

我的 GCMListener.class 文件:

public class GcmListener  extends GcmListenerService {

@Override
public void onMessageReceived(String from, Bundle data) {
    String message = data.getString("message");

    if (from.startsWith("/topics/bewegung")) {
        sendNotification(message);
    }

}
[...]

google-service.json 已经位于 /app.

马文

[编辑:] 知道了! 我在初始启动时注册了一个错误的主题。 现在它的工作完美。

您的清单中应该包含这 3 项服务。您错过了带有 com.google.android.c2dm.intent.RECEIVE

操作的那个
    <service
        android:name="com.myapppackage.application.gcm.GcmIntentService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>

    <service
        android:name="com.myapppackage.application.gcm.GcmIDListenerService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.gms.iid.InstanceID" />
        </intent-filter>
    </service>

    <service
        android:name="com.myapppackage.application.gcm.RegistrationIntentService"
        android:exported="false"/>