[英]GCM - Notification Payload shown but how to handle “click”
Ive implemented GCM using GCM Messaging Concepts and Options - Notifications and data in the message payload . 我已经使用GCM消息传递概念和选项 - 消息有效负载中的通知和数据实现了GCM。
Only-Data Payloads works well as expected. Only-Data Payloads按预期运行良好。 But now iam sending data and notification payload. 但现在我发送数据和通知有效负载。 The notification is shown on the device as expected. 通知按预期显示在设备上。 BUT how to handle the user clicks/touches the notification. 但是如何处理用户点击/触摸通知。 I know how to do that using the data
payload. 我知道如何使用data
有效负载。 How is this done using the notification
payload? 如何使用notification
有效负载完成此操作?
I found the answer by myself. 我自己找到了答案。 There is a property in the notifications payload that makes it possible to pass a action. 通知有效负载中有一个属性可以传递操作。
For example: 例如:
{
"data" : {
// some data
},
"notification" : {
// title, body etc
click_action = "com.my.click",
},
"id" : "id1"
}
<activity
android:name=".activities.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.my.click" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I believe what you are looking for is the create a PendingIntent in your NotificationBuilder function. 我相信你要找的是在你的NotificationBuilder函数中创建一个PendingIntent。 That way when the user clicks the Notification in notification bar it will launch that Pending Intent. 这样,当用户单击通知栏中的通知时,它将启动该Pending Intent。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.