Package com.google.android.gcm.server

Examples of com.google.android.gcm.server.Sender


        registrationIds.add(device.getRegistrationId());
      }
    }
    GcmMessage gcmMessage = (GcmMessage)pushMessage;
   
    Sender sender = new Sender(Application.get().getAppContext().getGoogleServerApiKey());
    Message.Builder messageBuilder = new Message.Builder();
    if (StringUtils.isNotEmpty(gcmMessage.getCollapseKey())) {
      messageBuilder.collapseKey(gcmMessage.getCollapseKey());
    }
    if (gcmMessage.isDelayWhileIdle() != null) {
      messageBuilder.delayWhileIdle(gcmMessage.isDelayWhileIdle());
    }
    if (gcmMessage.getTimeToLive() != null) {
      messageBuilder.timeToLive(gcmMessage.getTimeToLive());
    }
    for (Entry<String, String> entry : gcmMessage.getParameters().entrySet()) {
      if (entry.getValue() != null) {
        messageBuilder.addData(entry.getKey(), entry.getValue());
      }
    }
    Message message = messageBuilder.build();
    PushResponse pushResponse = new PushResponse();
    try {
      MulticastResult multicastResult = sender.send(message, Lists.newArrayList(registrationIds), 10);
     
      // analyze the results
      for (int i = 0; i < registrationIds.size(); i++) {
        Result result = multicastResult.getResults().get(i);
        Device device = devices.get(i);
View Full Code Here


   * Creates the {@link Sender} based on the servlet settings.
   */
  protected Sender newSender(ServletConfig config) {
    String key = (String) config.getServletContext()
        .getAttribute(ApiKeyInitializer.ATTRIBUTE_ACCESS_KEY);
    return new Sender(key);
  }
View Full Code Here

    log.severe("result = " + result.toString());
    return retObj;
  }

  private MulticastResult sendMessageToDevice(String apiKey, List<String> devices, String title, String message) {
    Sender sender = new Sender(apiKey);
    Message gcmMessage = new Message.Builder().addData("title", title).addData("message", message).build();
    MulticastResult result = null;
    try {
      result = sender.send(gcmMessage, devices, 3);
    } catch (IOException e) {
      //e.printStackTrace();
      log.severe(e.getMessage());
    }
    return result;
View Full Code Here

  private MulticastResult sendMessageToDevice(String apiKey, List<String> devices, String title, String message) {
    return sendMessageToDevice(apiKey, devices, title, message, null);
  }

  private MulticastResult sendMessageToDevice(String apiKey, List<String> devices, String title, String message, Map<String, String> extraMap) {
    Sender sender = new Sender(apiKey);
    Builder builder = new Message.Builder().addData("title", title).addData("message", message);
    if (null != extraMap) {
      for (String key : extraMap.keySet()) {
        builder.addData(key, extraMap.get(key));
      }
    }
    Message gcmMessage = builder.build();
    MulticastResult result = null;
    try {
      result = sender.send(gcmMessage, devices, 3);
    } catch (IOException e) {
      // e.printStackTrace();
      log.severe(e.getMessage());
    }
    return result;
View Full Code Here

                throw new IllegalStateException("can not find user "+username);
            }
            String registrationId = user.getAndroidId();
           
            if (registrationId!=null) {
                Sender sender = new Sender(myApiKey);
                Message.Builder message = new Message.Builder();
                for (Map.Entry<String, String> entry : data.entrySet()) {
                    message.addData(entry.getKey(), entry.getValue());
                }
                Result result = sender.send(message.build(), registrationId, 5);

                if (result.getMessageId() != null) {
                    String canonicalRegId = result.getCanonicalRegistrationId();
                    if (canonicalRegId != null) {
                        // same device has more than on registration ID: update database
View Full Code Here

  /**
   * Creates the {@link Sender} based on the servlet settings.
   */
  protected Sender newSender(ServletConfig config) {
    String key = (String) config.getServletContext().getAttribute(ApiKeyInitializer.ATTRIBUTE_ACCESS_KEY);
    return new Sender(key);
  }
View Full Code Here

    if (Logger.isDebugEnabled()) Logger.debug("time_to_live: " + time_to_live);

    if (Logger.isDebugEnabled()) Logger.debug("Custom Data: " + customData.toString());

    Sender sender = new Sender(apikey);
    Message msg = new Message.Builder().addData("message", message)
        .addData("custom", customData.toString())
        .collapseKey(collapse_key.toString())
        .timeToLive(time_to_live)
        .build();

    sender.send(msg, deviceid , 1);


    // icallbackPush.onError(e.getMessage());

    // icallbackPush.onSuccess();
View Full Code Here

  }

  public static void validateApiKey(String apikey) throws MalformedURLException, IOException, PushInvalidApiKeyException{
    Message message = new Message.Builder().addData("message", "validateAPIKEY")
        .build();
    Sender sender = new Sender(apikey);

    List<String> deviceid = new ArrayList<String>();
    deviceid.add("ABC");

    Map<Object, Object> jsonRequest = new HashMap<Object, Object>();
View Full Code Here

    private static final long serialVersionUID = 8171485458336202582L;

    private final ConcurrentHashMap<String, Sender> cache = new ConcurrentHashMap<String, Sender>();

    public Sender getSenderForAPIKey(String googleAPIKey) {
        Sender sender = cache.get(googleAPIKey);

        if (sender == null) {
            // create and cache:
            sender = new Sender(googleAPIKey);
            cache.put(googleAPIKey, sender);
        }

        return sender;
    }
View Full Code Here

        // send it out.....
        try {
            logger.log(Level.FINE, "Sending transformed GCM payload: " + gcmMessage);

            Sender sender = cache.getSenderForAPIKey(androidVariant.getGoogleKey());


            // GCM does only allow a 1000 device IDs
            while (! registrationIDs.isEmpty()) {
View Full Code Here

TOP

Related Classes of com.google.android.gcm.server.Sender

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.