android - 使用 GCM 推送通知和相应的聊天 Activity

标签 android google-cloud-messaging

我已经在我的应用程序中实现了 GCM,并且我已经通过两个 Android 设备进行了测试并且它可以正常工作。我正在我的应用程序中实现一个简单的聊天应用程序。我的应用程序实际上是在销售或购买产品。

当用户想要出价时,他输入消息并将其发送到服务器,gcm 被激活,卖家收到潜在客户的消息。当卖家点击收到的推送通知消息时,应该将他带到聊天 Activity 。通过这条简单的短信,我如何知道对应的是哪个产品?

最佳答案

我在评论中提到的,如果您通过服务器发送,您可以这样做:

$registatoin_ids = array($regId);
$message = array("message" => $message, "productId" => $uniqueProductId);

$result = $gcm->send_notification($registatoin_ids, $message);
echo $result;

然后在您的 Intent 服务中:

Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

String messageType = gcm.getMessageType(intent);
String message = extras.getString("message");
String productId = extras.getString("productId");

当你去建立你的通知时:

Intent productWindow = new Intent(this, ProductActivity.class);
productWindow.putExtra("productId", productId);
PendingIntent contentIntent = PendingIntent.getActivity(this,0,productWindow , 0);

关于android - 使用 GCM 推送通知和相应的聊天 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34638014/

相关文章:

android - GcmBroadcastReceiver 非法状态异常 : Not allowed to start service Intent

java - 如何仅在按下按钮时才重新加载 recyclerview?

java - 从 Android 手机获取电话号码

android - 我无法在 android 中显示本地存储中的图像

android - @EditText值开头

android - 使用 proguard 从 google play 服务中提取 GCM

java - GCM 多行通知

android - GCM、注册 ID 和处理用户登录/注销

android - 通知中的未决 Intent 未被清除

android - 如何在android中添加面板?