I am working on application which uses GCM service. I'm able to send notifications with code
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
And receiver in main activity is like
@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
}
When user1 sends data to another user via gcm notification, user2 received it and on select able to write to file at his device
I'm facing some problems like:
1. When User1 sends 3-4 messages continuously, all are showed separately because of mNotificationManager.notify(notifNo++, mBuilder.build());
, which i want to avoid and send list of all 3-4 msgs in sequence as a notification.
2. When user2 receives message through notification and is in same activity, avoid notification and write to file/ receive in activity directly.
Note: I'm doing this for multicast push notification, hence collapse key might not allow more than 4 users/messages when any of the users is offline.
Kindly pardon if repeating and post suggesting links.