Class GoogleFirebaseTool


  • public class GoogleFirebaseTool
    extends java.lang.Object
    Google Firebase toolbox
    • Method Summary

      Modifier and Type Method Description
      static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getAllDeviceTokens​(java.lang.String oneLogin)
      Search all users with device tokens
      static java.util.List<java.lang.String> getDeviceTokens​(java.lang.String login)
      List all registered device of a user
      static boolean init()
      Init Firebase service
      static void refreshToken​(Grant g, java.lang.String token, java.lang.String oldToken)  
      static void removeToken​(java.lang.String login, java.lang.String token)  
      static void sendMessage​(Grant g, java.lang.String title, java.lang.String body, java.lang.String icon, boolean allUsers, java.util.List<java.lang.String> logins, java.util.List<java.lang.String> groups, java.lang.String object, java.lang.String rowId)
      Send a message
      static void sendMessage​(Grant g, org.json.JSONObject data)
      Send a message
      static java.lang.String sendToAllUsers​(java.lang.String title, java.lang.String body, java.lang.String icon, java.util.Map<java.lang.String,​java.lang.String> map)
      Send a notification to 'allUsers' topic
      static java.lang.String sendToTopic​(java.lang.String topic, java.lang.String title, java.lang.String body, java.lang.String icon, java.util.Map<java.lang.String,​java.lang.String> map)
      Send a notification to single user
      static java.lang.String sendToUser​(java.lang.String login, java.lang.String token, java.lang.String title, java.lang.String body, java.lang.String icon, java.util.Map<java.lang.String,​java.lang.String> map)
      Send a notification to single user (token will be removed if unknown in Firebase)
      static void service​(Grant g, org.json.JSONObject data)  
      static void subscribeToTopic​(java.util.List<java.lang.String> tokens, java.lang.String topic)
      Subscribe a list of device tokens to topic on Firebase.
      static void syncTopics​(java.lang.String oneLogin)
      Synchronize topics
      static void unsubscribeFromTopic​(java.util.List<java.lang.String> tokens, java.lang.String topic)
      Unsubscribe a list of device tokens from topic on Firebase.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • service

        public static void service​(Grant g,
                                   org.json.JSONObject data)
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • refreshToken

        public static void refreshToken​(Grant g,
                                        java.lang.String token,
                                        java.lang.String oldToken)
      • removeToken

        public static void removeToken​(java.lang.String login,
                                       java.lang.String token)
      • init

        public static boolean init()
        Init Firebase service
        Returns:
        true if succeed
      • getDeviceTokens

        public static java.util.List<java.lang.String> getDeviceTokens​(java.lang.String login)
        List all registered device of a user
        Parameters:
        login - User login
        Returns:
        FIREBASE_TOKENS as json or null if no token found
      • getAllDeviceTokens

        public static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getAllDeviceTokens​(java.lang.String oneLogin)
        Search all users with device tokens
        Parameters:
        oneLogin - Optional login to limit search to one login
        Returns:
        Map of login = list of device tokens
      • sendMessage

        public static void sendMessage​(Grant g,
                                       org.json.JSONObject data)
                                throws java.lang.Exception
        Send a message
        Parameters:
        g - User rights
        data - Message data: title, message, icon, to: 'all' or { users:[logins], groups:[names]}, optional object, rowId
        Throws:
        java.lang.Exception
      • sendMessage

        public static void sendMessage​(Grant g,
                                       java.lang.String title,
                                       java.lang.String body,
                                       java.lang.String icon,
                                       boolean allUsers,
                                       java.util.List<java.lang.String> logins,
                                       java.util.List<java.lang.String> groups,
                                       java.lang.String object,
                                       java.lang.String rowId)
                                throws java.lang.Exception
        Send a message
        Parameters:
        g - User rights
        title - optional message title
        body - required message
        icon - optional icon
        allUsers - send to all users?
        logins - or specified logins?
        groups - or specified groups?
        object - optional business object
        rowId - optional object rowId
        Throws:
        java.lang.Exception
      • sendToAllUsers

        public static java.lang.String sendToAllUsers​(java.lang.String title,
                                                      java.lang.String body,
                                                      java.lang.String icon,
                                                      java.util.Map<java.lang.String,​java.lang.String> map)
                                               throws java.lang.Exception
        Send a notification to 'allUsers' topic
        Parameters:
        title - notification title
        body - notification body
        icon - optional icon (android)
        map - hidden pairs of key/value
        Returns:
        message Id or null on error
        Throws:
        java.lang.Exception
      • sendToUser

        public static java.lang.String sendToUser​(java.lang.String login,
                                                  java.lang.String token,
                                                  java.lang.String title,
                                                  java.lang.String body,
                                                  java.lang.String icon,
                                                  java.util.Map<java.lang.String,​java.lang.String> map)
                                           throws java.lang.Exception
        Send a notification to single user (token will be removed if unknown in Firebase)
        Parameters:
        login - User login
        token - User device token
        title - notification title
        body - notification body
        icon - optional icon (android)
        map - hidden pairs of key/value
        Returns:
        message Id or null on error
        Throws:
        java.lang.Exception
      • sendToTopic

        public static java.lang.String sendToTopic​(java.lang.String topic,
                                                   java.lang.String title,
                                                   java.lang.String body,
                                                   java.lang.String icon,
                                                   java.util.Map<java.lang.String,​java.lang.String> map)
                                            throws java.lang.Exception
        Send a notification to single user
        Parameters:
        topic - topic name
        title - notification title
        body - notification body
        icon - optional icon (android)
        map - hidden pairs of key/value
        Returns:
        message Id
        Throws:
        java.lang.Exception
      • syncTopics

        public static void syncTopics​(java.lang.String oneLogin)
        Synchronize topics
        Parameters:
        oneLogin - Optional login to synchronize one login or all users
      • subscribeToTopic

        public static void subscribeToTopic​(java.util.List<java.lang.String> tokens,
                                            java.lang.String topic)
                                     throws com.google.firebase.messaging.FirebaseMessagingException
        Subscribe a list of device tokens to topic on Firebase. Send by packet of 1000 to respect API limitation.
        Parameters:
        tokens - List of device tokens
        topic - Name of topic
        Throws:
        com.google.firebase.messaging.FirebaseMessagingException
      • unsubscribeFromTopic

        public static void unsubscribeFromTopic​(java.util.List<java.lang.String> tokens,
                                                java.lang.String topic)
                                         throws com.google.firebase.messaging.FirebaseMessagingException
        Unsubscribe a list of device tokens from topic on Firebase. Send by packet of 1000 to respect API limitation.
        Parameters:
        tokens - List of device tokens
        topic - Name of topic
        Throws:
        com.google.firebase.messaging.FirebaseMessagingException