【发布时间】:2016-03-17 17:38:28
【问题描述】:
我正在开发一个活动策划应用程序,并且我目前正在开发一项用于将项目分配给客人的功能。 分配物品后,会向客人推送通知,询问他是否可以携带所需物品。根据用户的输入,向服务器发送一个 HTTP 请求,更新项目的状态(带/不带)。
我有点卡在响应点击通知操作按钮上,因为我不太明白它是如何工作的。我设法显示了操作按钮,但不知道如何响应单击它们。正如我在网上看到的,对通知操作按钮的响应是由 PendingIntent 管理的,我无法理解它是如何工作的,以及如何使用它来根据单击的按钮发送 HTTP 请求。
我很高兴得到一些帮助和建议。
[这是发送给用户的通知示例。][
这是通知用户的方法:
private void notifyUser(Bundle data) {
...
//Notification configuration.
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(...)
.setLargeIcon(...)
.setContentTitle(...)
.setContentText(...)
.setAutoCancel(...)
.setSound(...);
//Get the item data from the request sent to the GCM server.
Item item = GsonFactory.getGson()
.fromJson(data.getString("data"), Item.class);
//This is the part that I do not understand...
notificationBuilder
.addAction(R.drawable.ic_close_black, "No", null)
.addAction(R.drawable.ic_done_black, "Yes", null);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
谢谢你!
【问题讨论】:
标签: android push-notification google-cloud-messaging