3
votes

Ive implemented GCM using GCM Messaging Concepts and Options - Notifications and data in the message payload.

Only-Data Payloads works well as expected. 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. How is this done using the notification payload?

2

2 Answers

-1
votes

I believe what you are looking for is the create a PendingIntent in your NotificationBuilder function. That way when the user clicks the Notification in notification bar it will launch that Pending Intent.

6
votes

I found the answer by myself. There is a property in the notifications payload that makes it possible to pass a action.

For example:

GCM Message

{
    "data" : {
        // some data
    },
    "notification" :  {
        // title, body etc
        click_action = "com.my.click",
    },
    "id" : "id1"
}

AndroidManifest

<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>

More Information

Notification payload support