现在我正在使用 3 台设备进行测试:Samsung S7500、Galaxy Mexus、HTC explore。如果设备处于活动状态,那么我会在所有三个设备中收到推送通知。如果它处于空闲状态(锁定/睡眠),那么我也会在所有三个设备中收到推送通知。但是,如果在发送推送消息时它处于脱机状态,那么我上线的时间应该会根据文档收到所有待处理的通知。但在这种情况下,我没有在所有设备中收到通知。特别是在 Galaxy Nexus 中,有时我会收到它是否处于空闲状态,有时不是。我哪里错了?谁能帮我?
从第三方服务器(.Net)端发布到 GCM 服务器的字符串:其中“i”是当前时间。
String postdata= "collapse_key=score_update"+i+"&time_to_live=2419200&delay_while_idle=1&data.message="+ message + "&data.time=" + System.DateTime.Now.ToString()
+ "®istration_id=" + deviceToken + "";
根据包括 Wakelock 在内的文档,在清单中提到了所有必需的权限。这是我在 GCMIntentService 类中的通知代码:
int icon = R.drawable.notif;
long when = System.currentTimeMillis();
NotificationManager notificationManager =(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification();
Intent notificationIntent = new Intent(context, DemoActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, (int) when,
notificationIntent,0);
RemoteViews contentView = new RemoteViews(getPackageName(),R.layout.notify);
contentView.setImageViewResource(R.id.ImageViewpnotify, icon);
contentView.setTextViewText(R.id.TextViewpnotify, message);
notification.contentView = contentView;
notification.contentIntent= intent;
notification.icon = icon;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.ledARGB = 0xffff0000;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.ledOnMS = 100;
notification.ledOffMS = 100;
notificationManager.notify((int)when, notification);