6

我有一个应用程序正在实现Google Cloud Messaging通知,但在特定设备中消息没有到达。此设备具有使用 GCM 的最低要求(Android 版本 2.2,已安装 Play 商店并已登录 Google 帐户)。在日志中,我看到该设备正在接收注册 ID 并发送到我有注册设备列表的后台。

我的问题是:我是否需要进行额外的配置才能使设备接收这些通知?

这是清单

<?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>
4

5 回答 5

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" />
于 2013-10-11T15:37:43.670 回答
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>
于 2014-01-28T15:36:44.620 回答
0

没有除了Android 2.2版本,安装了Play Store应用并登录了谷歌账号不需要其他配置,现在只剩下两种情况了

1) Either there is some ambiguity in your code. 
2) or may be it is a device specific issue.
于 2013-10-11T15:34:33.083 回答
0

我遇到了同样的问题。我的代码可以在 nexus4(Kitkat)上运行,但无法从 appln 服务器(通过 gcm 服务器)收到通知。对于低于 4.0.4 的版本,您应该确保您有 google在您的设备上设置帐户以使 gcm 正常工作。我的手机上有 Google 帐户,但我犯的错误是我的 Galaxy ace 中的帐户和同步设置为“关闭”。当我打开它并运行我的代码时,我收到了通知。

于 2013-11-25T01:25:28.400 回答
0

请检查以下解决方案。如果仍然不起作用,请告诉我。在两个不同的意图过滤器中添加 RECEIVE 和 REGISTRATION Intent

<receiver
            android:name=“&lt;.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=“&lt;Package Name>" />
            </intent-filter>
                 <intent-filter>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name=“&lt;Package Name>" />
            </intent-filter>
        </receiver>
        <service android:name=“&lt;.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)。

于 2014-03-26T13:00:56.917 回答