我在android設備中執行推送通知消息,並且遵循GCM文檔供我參考,並且我有通知本身中必須顯示按鈕並且用戶單擊它的情況將觸發相應的操作。android推送通知中的按鈕
從GCM文件,通知有效載荷,我們可以添加click_action當用戶觸摸通知來觸發動作......
如何顯示按鈕(像接受/拒絕)通知消息?
我在android設備中執行推送通知消息,並且遵循GCM文檔供我參考,並且我有通知本身中必須顯示按鈕並且用戶單擊它的情況將觸發相應的操作。android推送通知中的按鈕
從GCM文件,通知有效載荷,我們可以添加click_action當用戶觸摸通知來觸發動作......
如何顯示按鈕(像接受/拒絕)通知消息?
您可以在
Notification.Builder
中使用.addAction
。
Notification notification = new Notification.Builder(context)
// Show controls on lock screen even when user hides sensitive content.
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setSmallIcon(R.drawable.ic_stat_player)
// Add media control buttons that invoke intents in your media service
.addAction(R.drawable.ic_accept, "Accept", prevPendingIntent) // #0
.addAction(R.drawable.ic_reject, "Reject", pausePendingIntent) // #1
// Apply the media style template
EDIT 1
參考此link。
哪個Jar文件來自Notification.Builder ..我在gcm-server-1.0.2.jar中看不到任何類 –
它在'GCM'的服務類中。看看這個鏈接https://developer.android.com/guide/topics/ui/notifiers/notifications.html –
沒有辦法在通知消息中添加操作按鈕。這可能是稍後添加的功能,但目前不存在。
通知消息允許您創建一個非常特定類型的通知,如果你想有一個非常自定義的通知,那麼你應該使用數據消息(而不是通知消息),然後當收到消息時使用Notification.Builder用盡可能多的功能生成您的自定義通知:)
讓我告訴你一個暗示。現在谷歌正在使用Firebase Cloud Messaging,他們有很多教程來運行各種功能(推送通知,社交網絡登錄,雲數據庫等)。我真的推薦它:-) https://firebase.google.com/docs/ –