2013-10-11 66 views
6

我有一個應用程序,我正在實施Google Cloud Messaging通知,但是在特定設備中消息未到達。此設備具有使用GCM (Android版本2.2,安裝Play商店和記錄Google帳戶)的最低要求。在日誌中,我看到設備正在接收註冊ID並將其發送到後臺,在那裏我有已註冊設備的列表。沒有收到Google Cloud消息通知的特定設備

我的問題是:我是否需要進行額外的配置才能使設備接收這些通知?

這裏是清單

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="br.com.testegcm" 
    android:versionCode="1" 
    android:versionName="1" > 

    <uses-sdk 
     android:minSdkVersion="7" 
     android:targetSdkVersion="18" /> 

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 

    <permission android:name="com.example.gcm.permission.C2D_MESSAGE" 
     android:protectionLevel="signature" /> 
    <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" /> 

    <application 
     android:name="TesteGCM" 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" >   

     <receiver 
      android:name="br.com.testegcm.GcmBroadcastReceiver" 
      android:exported="true" 
      android:enabled="true" 
      android:permission="com.google.android.c2dm.permission.SEND" > 
      <intent-filter> 
       <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
       <category android:name="br.com.testegcm" /> 
      </intent-filter> 
     </receiver> 

     <service android:name="br.com.testegcm.GcmIntentService" /> 

     <activity 
      android:name="br.com.testegcm.Home" 
      android:screenOrientation="portrait" 
      android:label="@string/app_name" 
      android:theme="@style/notitle" > 

      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 

     </activity> 
</application> 
</manifest> 
+1

請包括您的代碼(清單,廣播接收器等)。清單中的一些錯誤可能會導致郵件不能僅在較早的Android版本上收到。 – Eran

+0

@Eran我包括清單 –

回答

0

沒有除了的Android 2.2版本,遊戲安裝商店應用和谷歌帳戶登錄不需要其他的配置,現在有隻有兩種情況左

1) Either there is some ambiguity in your code. 
2) or may be it is a device specific issue. 
3

更改此:

<permission android:name="com.example.gcm.permission.C2D_MESSAGE" 
    android:protectionLevel="signature" /> 
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" /> 

到:

<permission android:name="br.com.testegcm.permission.C2D_MESSAGE" 
    android:protectionLevel="signature" /> 
<uses-permission android:name="br.com.testegcm.permission.C2D_MESSAGE" /> 
+0

這不起作用 –

0

我有同樣的problem.My代碼將工作在nexus4(奇巧),但就輪不到我從申請服務器的通知(通過GCM服務器)。對於版本少於4.0.4你應該確保你的谷歌帳戶在你的設備上設置爲gcm工作。我的手機上有谷歌賬戶,但我犯的錯誤是我銀河王牌中的賬戶和同步設置爲'關'。當我打開它並運行我的代碼時,我收到了通知。

+1

在我的情況下,同步是ON,所以問題是不一樣的。 –

1

添加了同樣的問題,我最終我意識到,我需要在清單改變,從com.example.gcm廣播接收器組件的名字我的包名:

<!-- Push notifcations--> 
     <receiver 
       android:name=".BroadcastRecivers.GcmBroadcastReceiver" 
       android:permission="com.google.android.c2dm.permission.SEND"> 
      <intent-filter> 
       <action android:name="com.google.android.c2dm.intent.RECEIVE"/> 
       <category android:name="com.example.gcm"/> 
      </intent-filter> 
     </receiver> 

<!-- Push notifcations--> 
     <receiver 
       android:name=".BroadcastRecivers.GcmBroadcastReceiver" 
       android:permission="com.google.android.c2dm.permission.SEND"> 
      <intent-filter> 
       <action android:name="com.google.android.c2dm.intent.RECEIVE"/> 
       <category android:name="MY PACKAGE NAME"/> 
      </intent-filter> 
     </receiver> 
+0

謝謝!有趣的是,簡單而明顯的修復。在我的設備上工作> = API 19 w/top,但是直到我做出底部更改時才使用w/API 15。顯然後者更嚴格。我懶洋洋地複製了示例代碼,並沒有意識到我正在使用示例pkg名稱。 – sobelito

0

請檢查以下解決方案。如果仍然沒有工作,讓我知道。 增收和登記意圖在兩個不同的意圖過濾

<receiver 
      android:name=「<.GCM BroadcastReceiver Name>「 // Name of your BroadcastReceiver, define in code.                           
      android:exported="true" 
      android:permission="com.google.android.c2dm.permission.SEND" > 
      <intent-filter> 
       <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
       <category android:name=「<Package Name>" /> 
      </intent-filter> 
       <intent-filter> 
       <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
       <category android:name=「<Package Name>" /> 
      </intent-filter> 
     </receiver> 
     <service android:name=「<.GCM IntentService Name>" /> // Name of your IntentService, define in code. 
<meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 

添加如圖如上否則它不會對某些設備(實施例HTC)工作接收和登記意圖在兩個不同的意圖過濾。