我正在开发一个事件计划应用程序,目前正在开发一个功能,用于将物品分配给客人。
当物品被分配时,会向客人推送通知,询问他是否能带来所需的物品。根据用户输入,将向服务器发送HTTP请求,更新物品状态(带/不带)。
我遇到了一些问题需要解决。当我点击通知操作按钮时,我不太明白它是如何工作的。我设法显示操作按钮,但无法弄清如何响应单击它们。从网上看到的信息,通知操作按钮的响应由PendingIntent管理,但我无法理解它的工作原理,也不知道如何使用它根据单击的按钮发送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());
}
感谢您的提前感谢!