相关疑难解决方法(0)

处理Android上的Google Cloud Messaging中的注册ID更改

在Google Cloud Messaging的文档中,它指出:

Android应用程序应该存储此ID以供以后使用(例如,如果已经注册,则检查onCreate()).请注意,Google可能会定期刷新注册ID,因此您应该设计Android应用程序,并了解可能会多次调用com.google.android.c2dm.intent.REGISTRATION意图.您的Android应用程序需要能够做出相应的响应.

我使用以下代码注册我的设备:

GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String regID = gcm.register(senderID);
Run Code Online (Sandbox Code Playgroud)

GoogleCloudMessaging类封装了注册过程.那么我想如何处理com.google.android.c2dm.intent.REGISTRATION,因为处理是由GoogleCloudMessaging类在内部完成的?

android push-notification google-cloud-messaging

77
推荐指数
2
解决办法
6万
查看次数

在自动更新期间保持应用GCM注册ID有效

在官方文档和此问题中,Google建议重新注册GCM,因为注册ID可能会更改.

可能发生的一种假设方式是,在更新期间,全部是卸载然后安装.如果在该间隙期间收到GCM通知,则NotRegistered可以返回该GCM通知,并且GCM注册ID可能无效.

如果Google Play自动更新我的应用,那么处理这种情况并重新注册的最强大的方法是什么?在像WhatsApp这样的应用中,除非收到GCM通知,否则用户可能永远不会明确启动任何活动.因此,用户基本上"迷失",直到他意外地偶然发现了一项活动.

/sf/answers/1046871591/中,提到将包含"Canonical ID",以便第三方服务器可以更新注册ID.但是在文档中没有明确说明这种情况被覆盖(即GCM可能会在更新间隙中将应用程序误认为"已卸载",在这种情况下,在我看来,不会生成规范ID,而且我会直奔NotRegistered).

像WhatsApp或其他消息应用程序这样的"高可用性"应用程序如何处理这个问题?

android auto-update push-notification google-cloud-messaging

13
推荐指数
2
解决办法
1349
查看次数

Google Cloud Messaging注册ID到期

我正在为我的Android应用程序使用Google Cloud Messaging,我正在尝试了解注册ID何时到期.从这篇文章中我可以理解谷歌有时会刷新ID.我很好奇我的应用程序将如何知道id何时刷新?如果谷歌决定刷新ID,我的服务器直到将消息发送到旧ID,我不认为该消息将被发送.那么我每次都要尝试注册并查看ID是否相同?

同样的帖子说,当应用版本更改时,id会刷新,但是在通过清单更改版本时,注册ID不会更改.那么试图再次注册版本更改有什么意义呢?

编辑 这是服务器端.规范ID存储在哪里?

服务器端代码:

<?php
// Message to be sent
$message = $_POST['message'];
 
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
 
$fields = array(
                'registration_ids'  => array($_POST['registrationIDs']),
                'data'              => array( "message" => $message ),
                );
 
$headers = array( 
                    'Authorization: key=' . $_POST['apiKey'],
                    'Content-Type: application/json'
                );
 
// Open connection
$ch = curl_init();
 
// Set the url, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url );
 
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( …
Run Code Online (Sandbox Code Playgroud)

android google-cloud-messaging

9
推荐指数
1
解决办法
1万
查看次数

在GoogleCloudMessaging API中,如何处理注册ID的续订或到期?

问题是如何找出注册ID何时在GoogleCloudMessaging API中变为无效?我已经在类似主题的几个问题上阅读了答案:GCM注册ID是否到期?谷歌Coud Mesaging(GCM)和registration_id到期,我怎么知道?.这些问题的问题在于C2DM使用GCMRegistrar而不是GoogleCloudMessaging API的旧GCM API 的答案.前两种方法已经过折旧.

我会逐步打破我的困惑/疑问:

1)在标题Enable GCM下,在第二点它说:

Google may periodically refresh the registration ID, so you should design your Android application with the understanding that the com.google.android.c2dm.intent.REGISTRATION intent may be called multiple times. Your Android application needs to be able to respond accordingly.

The registration ID lasts until the Android application explicitly unregisters itself, or until Google refreshes the registration ID for …

java android google-cloud-messaging

5
推荐指数
1
解决办法
4752
查看次数