2012-08-23 214 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" /> 

此代碼爲我工作正常。