Android GCM不起作用

时间:2014-04-19 08:42:25

标签: android google-cloud-messaging

您好我已经创建了一个Android应用程序,我想要GCM注册ID。

但是我在获取GCM的注册ID时遇到错误。

我得到的错误就像 -

resetting backoff for idev.android.rchat

我已将以下代码添加到我的主要活动的onCreate中:

    GCMRegistrar.checkDevice(this);
    GCMRegistrar.checkManifest(this);
    final String regId = GCMRegistrar.getRegistrationId(this);
    if (regId.equals("")) 
    {          
        GCMRegistrar.register(this, SENDER_ID);
    }

    Log.v("REG ID:",""+regId);

清单文件是 -

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

 <permission
    android:name="idev.android.rchat.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

 <permission
    android:name=".permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="17" />

<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<!-- Requires OpenGL ES version 2 -->
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />    

<uses-permission android:name="idev.android.rchat.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />    
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

<uses-permission android:name=".permission.C2D_MESSAGE" />
<uses-permission android:name=".permission.RECEIVE" />

<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


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

    <activity
        android:name="idev.android.rchat.Splash_Screen"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

     <activity
        android:name="idev.android.rchat.Login"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >            
    </activity> 

    <!-- Goolge API Key -->
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="key" />

    <meta-data
        android:name="com.google.android.gms.version"  
        android:value="@integer/google_play_services_version" />
    <!-- GCM -->
    <receiver
        android:name="idev.android.other.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter> 
            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <!-- Receives the registration id. -->
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="idev.android.rchat" />
        </intent-filter>
    </receiver>

    <service android:name="idev.android.other.GCMIntentService" />

</application>

1 个答案:

答案 0 :(得分:0)

我认为您将获得注册ID为null。我遇到同样的问题我通过以下本教程程序解决了这个问题,它将被解决。

http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

并再记下一点 .GcmIntentservices 必须在应用程序的根软件包中,您必须将其放在idev.android.rchat上,然后才能正常工作。