未收到Android c2dm消息

时间:2011-10-31 05:41:40

标签: android push-notification android-c2dm

当我尝试在我的设备中接收消息时,我遇到了问题,一切正常,但是当我尝试接收它时,没有任何结果,我得到了:

ID = 0:1319039498507602%b50b7d2400000031

来自https://android.apis.google.com/c2dm/send

这意味着发送的消息不是吗?

但我无法在设备中收到它。 清单: -

> <?xml version="1.0" encoding="utf-8"?> <manifest
> xmlns:android="http://schemas.android.com/apk/res/android"
>       package="com.cgt.pushn"
>       android:versionCode="1"
>       android:versionName="1.0">
>        <permission android:name="com.cgt.pushn.permission.C2D_MESSAGE" android:protectionLevel="signature" />    <uses-permission
> android:name="com.cgt.pushn.permission.C2D_MESSAGE" />
> 
>    <!-- This app has permission to register and receive message -->   
> <uses-permission
> android:name="com.google.android.c2dm.permission.RECEIVE" />
> 
>    <!-- Send the registration id to the server -->    <uses-permission
> android:name="android.permission.INTERNET" />
>       <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
> <uses-permission android:name="android.permission.USE_CREDENTIALS" />
> <uses-permission android:name="android.permission.READ_PHONE_STATE" />
> 
>     <application android:icon="@drawable/icon" android:label="@string/app_name" >
>     <activity android:name=".pushtest"
>                   android:label="@string/app_name">
>             <intent-filter>
>                 <action android:name="android.intent.action.MAIN" />
>                 <category android:name="android.intent.category.LAUNCHER"/>
>             </intent-filter>
>         </activity> <!--        android:name="com.google.android.c2dm.C2DMBroadcastReceiver" -->
> 
>    <receiver android:name=".BroadcastReciever"
> android:permission="com.google.android.c2dm.permission.SEND"> <!--    
> -->
>           <intent-filter>
>               <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
>               <category android:name="com.cgt.pushn" />
>           </intent-filter>
>           <!-- Receive the registration id -->
>           <intent-filter>
>               <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
>               <category android:name="com.cgt.pushn"/>
>           </intent-filter>
>       </receiver>
>     </application>
>     <uses-sdk android:minSdkVersion="8" />
> 
> </manifest>
有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

你忘了写服务标签了。在接收器标签上方输入以下标签。

    <!-- In order to use the c2dm library, an
     application must declare a class with the name C2DMReceiver, in its 
     own package, extending com.google.android.c2dm.C2DMBaseReceiver -->

     <service android:name=".C2DMReceiver"/> 

见下面的链接

      http://www.johnhawthorn.com/2010/12/android-cloud-to-device-messaging-1/