I was able to create push notification after following this tutorial, but when I click on the notification it opens the messaging app but I dont know who sent a message to me, I wanted to know if there is a way to know who sent it, content of message if possible and if I click on the notification can it directly go to chat with that person.
to see what GCM is sending I added the following to gcmintentservice :
public class GcmIntentService extends IntentService {
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
public GcmIntentService() {
super("GcmIntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
String action = intent.getAction();
if (action.equals("com.google.android.c2dm.intent.RECEIVE")) {
handleMessage(intent);
}
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, LoginActivity.class), 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("New Message!");
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
private void handleMessage(Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Set<String> keys = bundle.keySet();
Iterator<String> it = keys.iterator();
Log.e("message","Dumping Intent start");
while (it.hasNext()) {
String key = it.next();
Log.e("message","[" + key + "=" + bundle.get(key)+"]");
}
Log.e("message","Dumping Intent end");
}
}`
}
and the log message I get is :
E/message﹕ Dumping Intent start
E/message﹕ [from=551512823036]
E/message﹕ [android.support.content.wakelockid=2]
E/message﹕ [collapse_key=do_not_collapse]
E/message﹕ Dumping Intent end
but I cant see sender_id
If you're using the sample backend provided in the tutorial (https://github.com/sinch/push-backend-ruby), you're not sending the sender_id to the server. You'll also need to update the backend logic to handle the incoming sender_id, and include it in the GCM options.