GCM 中的注册 id 是什么,如何获取推送通知的注册 id?你能解释一下吗。
问问题
147 次
1 回答
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" />
此代码适用于我。
于 2012-09-14T10:31:17.040 回答