PushPlugin-deprecated icon indicating copy to clipboard operation
PushPlugin-deprecated copied to clipboard

Allow unique notification icons for separate notifications

Open anyandallart opened this issue 11 years ago • 0 comments

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: https://github.com/thenewmr/PushPlugin/commit/728e975442e45668b7d809aec028396a9b023dfa

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

anyandallart avatar Mar 23 '14 17:03 anyandallart