Skip to content

Instantly share code, notes, and snippets.

@seymores
Last active September 9, 2017 13:54
Show Gist options
  • Save seymores/5575940 to your computer and use it in GitHub Desktop.
Save seymores/5575940 to your computer and use it in GitHub Desktop.
Use gcm-server from clojure
;;; Project here: https://github.com/seymores/gcm-clj
;;;
;;; Note: you need to specify the custom repo to get gcm-server.jar
;;; :repositories [["google" "https://github.com/slorber/gcm-server-repository/raw/master/releases"]]
;;; :dependencies [[com.google.android.gcm/gcm-server "1.0.2"]]
;;;
;;; See http://developer.android.com/google/gcm/gs.html#server-app
;; Import all the needed classes from gcm-server.jar
(import (com.google.android.gcm.server Sender Message Message$Builder MulticastResult))
(def API_KEY "xxxxxxxxxxxxxxxxxxxxxxxx...vz") ;Use your API KEY here
(def sender (Sender. API_KEY))
(defn notify
"Send notification with the given message to the specific device"
[message deviceRegId retryCount]
(.send sender message deviceRegId retryCount))
(def devId "1jGmalO_K9bPrprKlH4...GTX9EtRDbCZDocdRR5qxxxxxx") ; Get from your device during gcm registration
(def msg (-> (Message$Builder.) (.addData "key" "Updates") .build))
;; Look ma, no classes!
(notify msg devId 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment