2016-08-21 17 views
0

我試圖讓GCM推送通知在我的Android 6.0.1設備上工作。不幸的是我遇到了一個錯誤。 日誌說:GCM無法解析目標意向服務

E/FirebaseInstanceId:無法解析目標意圖的服務,跳躍類名執法 E/FirebaseInstanceId:錯誤,同時提供消息:ServiceIntent未找到。

但我沒有使用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); 
    } 

} 
[...] 

谷歌,service.json已經位於/應用程序。

馬文

[編輯:] 明白了! 我在初次啓動時註冊了一個錯誤的主題。 現在它的工作非常完美。

+0

你能收到通知的人嗎? –

+0

@SohailZahid我可以註冊我的應用程序並訂閱一個主題,但提到的錯誤是在收到通知時引發的。 – Melvin

+1

好心地不接受我的回答,所以我可以刪除,因爲它不正確的答案,並不會幫助其他反而會混淆他們。 –

回答

-3

您應該在清單中包含這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"/> 

source thread.

+0

我的清單中有所有這3種服務。 – Melvin

+0

@Melvin那麼爲什麼這個接受的答案? –

+0

@EugenPechanec不是解決方案,但給了我改進的想法,我認爲這是一個常見的錯誤。 – Melvin