0

遵循本教程后,我能够创建推送通知,但是当我单击通知时,它会打开消息传递应用程序,但我不知道是谁向我发送了消息,我想知道是否有办法知道是谁发送的,如果可能的话,消息的内容,如果我点击通知,它可以直接与那个人聊天。

要查看 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﹕Dumping Intent start

E/message:[来自=551512823036]

E/message:[android.support.content.wakelockid=2]

E/message:[collapse_key=do_not_collapse]

E/message﹕Dumping Intent end

但我看不到 sender_id

4

2 回答 2

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

于 2015-06-11T18:09:56.413 回答
0

如果您使用教程中提供的示例后端 ( https://github.com/sinch/push-backend-ruby ),则不会将 sender_id 发送到服务器。您还需要更新后端逻辑以处理传入的 sender_id,并将其包含在 GCM 选项中。

于 2015-06-12T17:27:34.343 回答