2
我正尝试使用GCM在我的应用中使用推送通知。我打电话给GCMRegistrar.register(this, SENDER_ID)
,但我遇到了一个错误。Android GCM注册失败。为什么?
我的清单文件:
<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="com.salamworld"/>
</intent-filter>
</receiver>
<service android:name=".GCMIntentService"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<permission android:name="my.package.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="my.package.permission.C2D_MESSAGE"/>
<uses-sdk android:minSdkVersion="8"/>
而这里的错误:
DEBUG/GCMBaseIntentService(423): Registration error: ACCOUNT_MISSING
我GCMIntentService类:
public class GCMIntentService extends GCMBaseIntentService{
public GCMIntentService() {
super();
}
@Override
protected void onMessage(Context context, Intent intent) {
}
@Override
protected void onError(Context context, String errorId) {
}
@Override
protected void onRegistered(Context context, String registrationId) {
Log.d("@[email protected]", registrationId);
}
@Override
protected void onUnregistered(Context context, String registrationId) {
}
}
其实,我在模拟器上运行。我该怎么做 – 2012-07-20 04:46:20
你最好在设备上试试,因为你的模拟器在默认情况下没有被配置为拥有谷歌账户。 [你也可以检查这个答案](http://stackoverflow.com/a/3796495/726863) – 2012-07-20 04:48:23
哦,非常感谢! – 2012-07-20 05:31:18