我可以在关注此tutorial之后创建推送通知,但是当我点击通知时它会打开消息应用程序,但我不知道是谁向我发送了消息,我想知道是否有消息如果可能的话,知道是谁发送邮件的方式,邮件的内容,如果我点击通知,它可以直接与该人聊天。
要查看GCM发送的内容,我将以下内容添加到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");
}
}`
}
我收到的日志消息是:
E / message:倾倒意图开始
电子邮件:[来自= 551512823036]
E / message:[android.support.content.wakelockid = 2]
电子邮件:[collapse_key = do_not_collapse]
E / message:倾倒意图结束
但我看不到sender_id
答案 0 :(得分:0)
查看您收到的消息,应该有一个发件人ID。
请参阅此处以获取有关该消息的文档 http://download.sinch.com/docs/android/latest/reference/index.html http://download.sinch.com/docs/android/latest/reference/com/sinch/android/rtc/messaging/Message.html
答案 1 :(得分:0)
如果您正在使用教程中提供的示例后端(the analysis done here),则不会将sender_id发送到服务器。您还需要更新后端逻辑以处理传入的sender_id,并将其包含在GCM选项中。