2013-10-11 64 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)工作接收和登记意图在两个不同的意图过滤。