Android GCM 注册失败。为啥?
Posted
技术标签:
【中文标题】Android GCM 注册失败。为啥?【英文标题】:Android GCM registration failed. Why?Android GCM 注册失败。为什么? 【发布时间】:2012-07-20 04:38:49 【问题描述】:我试图使用 GCM 在我的应用程序中提供推送通知。我打电话给GCMRegistrar.register(this, SENDER_ID)
,但我遇到了错误。
我的清单文件:
<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):注册错误: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("@R@", registrationId);
@Override
protected void onUnregistered(Context context, String registrationId)
【问题讨论】:
【参考方案1】:当您的设备中没有 Google 帐户时会出现此例外情况,
ACCOUNT_MISSING - 手机上没有 Google 帐户。安卓 应用程序应该要求用户打开帐户管理器并添加一个 谷歌帐户。在设备端修复。
【讨论】:
其实我是在模拟器上运行的。我该怎么办 您最好在设备中尝试,因为您的模拟器默认情况下未配置为拥有 google 帐户。 You can also check this answer @servus-libertatem 您可以在模拟器中添加 Google 帐户。确保您已使用 Google API(无论是 API 级别)创建了一个模拟器。 但没有谷歌帐户如何从Play商店下载应用程序以上是关于Android GCM 注册失败。为啥?的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Java GCM API 在 android 设备上获取失败推送通知的注册 ID
为啥 GCM 会为某些 android 设备返回空的注册 ID?
为啥启动 StreamingContext 失败并显示“IllegalArgumentException:需求失败:未注册输出操作,因此没有可执行的操作”?