【发布时间】:2015-09-13 07:56:22
【问题描述】:
我正在开发使用 GCM 服务的应用程序。 我可以使用代码发送通知
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent msgMainActivity = new Intent(this, MainActivity.class);
msgMainActivity.putExtra("msg", msg);
msgMainActivity.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,msgMainActivity, PendingIntent.FLAG_CANCEL_CURRENT);
// contentIntent.
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("appName Notification")
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(sndr+": "+msg)
.setNumber(notifNo); //static id notifNo
// Set notification sound
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
mBuilder.setSound(alarmSound);
mBuilder.setAutoCancel(true);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(notifNo++, mBuilder.build()); // separate notifications each time
主要活动中的接收者就像
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Bundle notificationData = intent.getExtras();
String notifMessage = notificationData.getString("msg");
// rest code for appending notifMessage in file.txt
}
当用户 1 通过 gcm 通知向另一个用户发送数据时,用户 2 收到了它并且在选择时可以在他的设备上写入文件
我面临一些问题,例如:
1.当User1连续发送3-4条消息时,由于mNotificationManager.notify(notifNo++, mBuilder.build());,所有消息都单独显示,我想避免这种情况并按顺序发送所有3-4条消息的列表作为通知。
2.当user2通过notification收到消息并且在同一个activity中时,避免notification直接写入文件/在activity中接收。
注意:我这样做是为了多播推送通知,因此当任何用户离线时,折叠键可能不允许超过 4 个用户/消息。
如果重复并发布建议链接,请原谅。
【问题讨论】:
标签: android notifications push-notification google-cloud-messaging