2012-08-23 168 views

回答

0

在代码 -

GCMRegistrar.checkManifest(this); 
GCMRegistrar.checkDevice(this); 
GCMRegistrar.register(this, SENDER_ID);//this line just initiates the process of registration and the onRegistered() of GCMBaseIntentService will be called when regId is assigned 
String regId = GCMRegistrar.getRegistrationId(this); 

在Manifest-

<receiver 
    android:name="com.google.android.gcm.GCMBroadcastReceiver" 
    android:permission="com.google.android.c2dm.permission.SEND" > 
     <intent-filter> 
      <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
      <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
      <category android:name="package name" /> 
     </intent-filter> 
</receiver> 

添加上述应用标签。

添加一些权限受过良好

<permission 
android:name="com.vaayoo.android.pushnotify.shail.permission.C2D_MESSAGE" 
android:protectionLevel="signature" /> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
<uses-permission android:name="com.vaayoo.android.pushnotify.shail.permission.C2D_MESSAGE"/> 
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 

此代码为我工作正常。