gpt4 book ai didi

Android、Google Cloud Messaging - 推送到手机,但不会在设备上创建推送通知

转载 作者:行者123 更新时间:2023-11-29 21:56:51 25 4
gpt4 key购买 nike

我一直在尝试让 Google Cloud Messaging 创建推送通知。我能够注册设备,将注册 ID 存储在服务器上,然后将推送消息发送回设备。

我能够做到所有这些,并且 catLog 显示推送消息已到达设备。但是在设备上没有出现推送通知消息。

这可能是什么原因?

以防万一,这是我注册设备的方式:

        GCMRegistrar.checkDevice(this); 
GCMRegistrar.checkManifest(this);

final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals(""))
{
// Automatically registers application on startup.
GCMRegistrar.register(getApplicationContext(), SENDER_ID);
}
else
{
// Device is already registered on GCM, check server.
if (GCMRegistrar.isRegisteredOnServer(getApplicationContext()))
{
// Not sure what to do here :)
}
else
{
if ( user_id != null )
{
GCMRegistrar.register(this, SENDER_ID); // google register
setRegistrationId ( user_id , regId ); // saves id on server
}
}
}

结束 onPostExecute 我做 GCMRegistrar.setRegisteredOnServer(getApplicationContext(), true);

这是我的 GCMIntentService 中的 onMessage() 方法

  @Override
protected void onMessage(Context ctxt, Intent message) {
Bundle extras=message.getExtras();

for (String key : extras.keySet()) {
Log.d(getClass().getSimpleName(),
String.format("onMessage: %s=%s", key,
extras.getString(key)));
}
}

这可能是问题所在吗?实际上应该如何?

谢谢!

最佳答案

What could be the cause of this?

这里有一些可能性:

  1. 您的应用中没有 GCMIntentService 子类。

  2. 你这样做了,但它没有在 list 中注册。

  3. 你这样做了,但你没有覆盖 onMessage()

  4. 你做到了,但你的 onMessage() 没有正确记录事件或以其他方式让你知道事件发生了。

关于Android、Google Cloud Messaging - 推送到手机,但不会在设备上创建推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13022614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com