GCM中的注册ID是什么,如何获取推送通知的注册ID? 你可以解释一下。
答案 0 :(得分: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);
在清单中 -
<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" />
此代码适合我。