GcmBroadcastReceiver未收到任何通知

时间:2014-02-17 10:21:16

标签: android google-cloud-messaging

请阅读上次编辑说明,问题已解决。

我已根据GCM官方文档中的指示设置了GCM代码。

我能够 1.注册设备并接收注册ID。 2.创建了API项目并能够从服务器发送消息,结果成功为 -

{"multicast_id":7210001445807628862,"success":2,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1392631541038778%b06e6126f9fd7ecd"},{"message_id":"0:1392631541037185%b06e6126f9fd7ecd"}]}
  1. 但是,没有收到通知!!
  2. 我搜索了很多,但我不知道什么是错的!请帮助!!

    以下是代码

    清单

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.techlovejump.gcm"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="9"
            android:targetSdkVersion="17" />
    
        <uses-permission android:name="android.permission.INTERNET" />
        <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.techlovejump.gcm.permission.C2D_MESSAGE"
            android:protectionLevel="signature" />
    
        <uses-permission android:name="com.techlovejump.gcm.permission.C2D_MESSAGE" />
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.techlovejump.gcm.MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
            <receiver
                android:name="com.techlovejump.gcm.GcmBroadcastReceiver"
                android:permission="com.google.android.c2dm.permission.SEND" >
                <intent-filter>
                    <!-- Receives the actual messages. -->
                    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                    <category android:name="com.techlovejump.gcm" />
                </intent-filter>
            </receiver>
    
            <service android:name="com.techlovejump.gcm.GcmIntentService" />
    
            <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />
    
            <activity
                android:name="com.techlovejump.gcm.ReceiveActivity"
                android:label="@string/title_activity_receive" >
            </activity>
        </application>
    
    </manifest>
    

    GcmBroadcastReceiver.java

    package com.techlovejump.gcm;
    
    import android.app.Activity;
    import android.content.ComponentName;
    import android.content.Context;
    import android.content.Intent;
    import android.support.v4.content.WakefulBroadcastReceiver;
    
    public class GcmBroadcastReceiver extends WakefulBroadcastReceiver{
    
        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
    
            // Explicitly specify that GcmIntentService will handle the intent.
            ComponentName comp = new ComponentName(context.getPackageName(),
                    GcmIntentService.class.getName());
            // Start the service, keeping the device awake while it is launching.
            startWakefulService(context, (intent.setComponent(comp)));
            setResultCode(Activity.RESULT_OK);
    
        }
    }
    

    修改 此问题与代码相关的 NOT

    由Dan在链接上发现和回答 How to track GCM Problems?

    我不得不关掉WiFi并使用电话移动网络来收到通知。 我不确定为什么它不能用于Wifi;但对我来说就是这样......

    由于

0 个答案:

没有答案