很遗憾您不能。你要做的是
在通知到达时获取历史记录。历史记录返回一个json,如果添加了新消息,它包含一个'messagesAdded'。
您可以保留predefined array of labels,如下所示
predefinedLabels = ['UNREAD', 'CATEGORY_PERSONAL', 'INBOX']
现在你可以检查了,(each is the history json)
if 'messagesAdded' in each:
labels = each["messagesAdded"][0]["message"]["labelIds"]
intersectionOfTwoArrays = list(set(predefinedLabels) & set(labels))
您可以在此处获得intersection of labels。现在您必须使用predefined labels 进行检查
if set(predefinedLabels) == set(intersectionOfTwoArrays):
#get the messageId and do what you want
终于可以filter the notification随心所欲了!
最好存储histroyId 并在每次更新时更新它
notification 并在获得 history 时使用它。它会帮助你
仅获取更新的历史记录。
请注意,我在构建服务器时使用了python。所以上面使用python写的demo代码