Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow unique notification icons for separate notifications #6

Open
wants to merge 135 commits into
base: master
Choose a base branch
from
Open

Allow unique notification icons for separate notifications #6

wants to merge 135 commits into from

Conversation

anyandallart
Copy link

Modeled after Facebook / Google Hangouts ability for each notification to have a different icon depending on the message (i.e. if you get a message from Jan, Jan's picture shows up as the notification icon, if you get a message from Bill, Bill's picture shows up as the notification icon, etc.).

Just pass the url of the image you want to show up for that particular notification as the variable "icon" in your GCM request. Works like this in the GCM request:
(modeled after http://stackoverflow.com/questions/11242743/gcm-with-php-google-cloud-messaging)

extras.getString("message"); */ $message = "Life is incredibly exciting ...."; $title="You have a message."; // Set POST variables. $url = 'https://android.googleapis.com/gcm/send'; $icon='http://www.example.com/BillsProfilePicture.jpg'; $fields = array( 'registration_ids' => $registrationIDs, 'data' => array( "message" => $message, "title" => $title, "notId"=>'300', "icon"=>$icon ) ); $headers = array( 'Authorization: key=' . $apiKey, 'Content-Type: application/json' ); // Open connection $ch = curl_init(); // Set the url, number of POST vars, POST data curl_setopt( $ch, CURLOPT_URL, $url ); curl_setopt( $ch, CURLOPT_POST, true ); curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) ); // Execute post $result = curl_exec($ch); // Close connection curl_close($ch); // Echo success or failure echo $result; ?>

Also, FYI, I merged the code from TheNewMR from here to allow for stacked notifications depending on different notification ID's:
thenewmr@728e975

Instructions for how that works are on that page, however in case it gets deleted for some reason I'll copy/paste here:

"This allows for multiple notifications to be displayed on Android. Simply add data with key "notId" and an integer value when sending via GCM. Differentiate between different notifications by setting different notIds. Defaults to 0 if not key supplied."

bobeast and others added 30 commits December 4, 2012 11:35
Fix apple link.
You need to add android.permission.GET_TASKS. 
Without this permission, the application crashes when it receives PUSH NOTIFICATION.
scotthooker and others added 30 commits October 31, 2013 17:21
Allow the plugin to know when the app is no longer in foreground so that it may receive push notifications
#85 No notifications in android when the app is closed
We can rely on the the other activity functions setting foreground to be true
We should always send a notification this is better than never sending one
adds android.permission.VIBRATE needed for android 2.3.x
json key should be surrounded by quotation
Fixed quotes unescaping for non string values
Added instrucction to Android manual installation
**NOTE: For this to work you must also modify PushHandlerActivity.java as indicated in this fork.

Modeled after Facebook / Google Hangouts ability for each notification to have a different icon depending on the message (i.e. if you get a message from Jan, Jan's picture shows up as the notification icon, if you get a message from Bill, Bill's picture shows up as the notification icon, etc.).

Just pass the url of the image you want to show up for that particular notification as the variable "icon" in your GCM request. Works like this in the GCM request:
(modeled after http://stackoverflow.com/questions/11242743/gcm-with-php-google-cloud-messaging)

<?php
// Replace with real BROWSER API key from Google APIs
$apiKey = "asAdds235fsdfsdf2342aEl3432534634BNgg";

// Replace with real client registration IDs. Put the correct registration id you are getting from app. If you are using eclipse check your logcat you will get it there.
$registrationIDs = array( "APA91bHpXL6QHMUMVjR1WB3sNTwCEj243434342525345LXAR2Mwp6KJKmTTp9hqE-b57683424233YjMJH5vZIEtbNbyUWOVQhS5gFEjJQLYs5pvEdqpPkHn9VeFp1A" );

/* Message to be sent - Make sure that message is the key you are using in GCMIntentService.java onMessage() ->  extras.getString("message"); */

$message = "Life is incredibly exciting ....";
$title="You have a message.";

// Set POST variables.
$url = 'https://android.googleapis.com/gcm/send';
$icon='http://www.example.com/BillsProfilePicture.jpg';

$fields = array(
  'registration_ids'  => $registrationIDs,
  'data'              => array( "message" => $message, "title" => $title, "notId"=>'300', "icon"=>$icon ) 
);

$headers = array( 
     'Authorization: key=' . $apiKey,
     'Content-Type: application/json'
);

// Open connection
$ch = curl_init();

// Set the url, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url );

curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );

// Execute post
$result = curl_exec($ch);

// Close connection
curl_close($ch);

// Echo success or failure
echo $result;

?>


**********************

Also, FYI, I merged the code from TheNewMR from here to allow for stacked notifications depending on different notification ID's:
thenewmr@728e975

Instructions for how that works are on that page, however in case it gets deleted for some reason I'll copy/paste here: 

"This allows for multiple notifications to be displayed on Android.  Simply add data with key "notId" and an integer value when sending via GCM.  Differentiate between different notifications by setting different notIds.  Defaults to 0 if not key supplied."
Just send a push with the GCM variable cancelNotification set (can be set to anything) and the notification will be dismissed. Default functionality uses the standard NOTIFICATION_ID=237.

The code addition also works with the the code from TheNewMR (thenewmr@728e975) which allows for stacked notifications depending on different notification ID's. To dismiss a Notification ID just make sure to set the GCM variable cancelNotification and to set notId to the notification ID you want to dismiss.
Just send a push with the GCM variable cancelNotification set (can be set to anything) and the notification will be dismissed. Default functionality uses the standard NOTIFICATION_ID=237.

The code addition also works with the the code from TheNewMR (thenewmr/PushPlugin@728e975) which allows for stacked notifications depending on different notification ID's. To dismiss a Notification ID just make sure to set the GCM variable cancelNotification and to set notId to the notification ID you want to dismiss.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.