当前位置: 首页>>代码示例>>Java>>正文


Java Constants类代码示例

本文整理汇总了Java中com.google.android.gcm.server.Constants的典型用法代码示例。如果您正苦于以下问题:Java Constants类的具体用法?Java Constants怎么用?Java Constants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Constants类属于com.google.android.gcm.server包,在下文中一共展示了Constants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendMessage

import com.google.android.gcm.server.Constants; //导入依赖的package包/类
public void sendMessage(List<String> registrationIds, Message message) throws IOException  {
    mLog.info("Sending to " + registrationIds.size() + " clients message " + message);
    for (String registrationId : registrationIds) {
        // sendNoReply otherwise a device switched off will receive the message the same
        Result result = mSender.sendNoRetry(message, registrationId);
        if (result.getMessageId() != null) {
            mLog.info("Message sent to " + registrationId);
            String canonicalRegId = result.getCanonicalRegistrationId();
            if (canonicalRegId != null) {
                // if the regId changed, we have to update the datastore
                mLog.info("Registration Id changed for " + registrationId + " updating to " + canonicalRegId);
                mRegistrationDao.updateRegistrationId(registrationId, canonicalRegId);
            }
        } else {
            String error = result.getErrorCodeName();
            if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
                mLog.warning("Registration Id " + registrationId + " no longer registered with GCM, removing from datastore");
                // if the device is no longer registered with Gcm, remove it from the datastore
                mRegistrationDao.removeByRegistrationId(registrationId);
            } else {
                mLog.warning("Error when sending message : " + error);
            }
        }
    }
}
 
开发者ID:rainbowbreeze,项目名称:playtogether,代码行数:26,代码来源:GcmMessageHelper.java

示例2: extractGCMTopics

import com.google.android.gcm.server.Constants; //导入依赖的package包/类
/**
 * Extracts GCM topic names out of a given Criteria object (e.g. /topics/nameOfcategory).
 * If the Criteria is empty, the given variant ID will be returned as topic name (/topics/variantID)
 *
 * @param criteria the push message filter criteria
 * @param variantID variant ID, used as global fallback GCM topic name
 *
 * @return GCM topic names for the given push message criteria filter.
 */
public static Set<String> extractGCMTopics(final Criteria criteria, final String variantID) {
    final Set<String> topics = new TreeSet<>();

    if (isEmptyCriteria(criteria)) {
        // use the variant 'convenience' topic
        topics.add(Constants.TOPIC_PREFIX + variantID);

    } else if (isCategoryOnlyCriteria(criteria)) {
        // use the given categories
        topics.addAll(criteria.getCategories().stream()
                .map(category -> Constants.TOPIC_PREFIX + category)
                .collect(Collectors.toList()));
    }
    return topics;
}
 
开发者ID:aerogear,项目名称:aerogear-unifiedpush-server,代码行数:25,代码来源:TokenLoaderUtils.java

示例3: processFCM

import com.google.android.gcm.server.Constants; //导入依赖的package包/类
/**
 * Process the HTTP POST to the FCM infrastructure for the given list of registrationIDs.
 */
private void processFCM(AndroidVariant androidVariant, List<String> pushTargets, Message fcmMessage, ConfigurableFCMSender sender) throws IOException {


    // push targets can be registration IDs OR topics (starting /topic/), but they can't be mixed.
    if (pushTargets.get(0).startsWith(Constants.TOPIC_PREFIX)) {

        // perform the topic delivery

        for (String topic : pushTargets) {
            logger.info(String.format("Sent push notification to FCM topic: %s", topic));
            Result result = sender.sendNoRetry(fcmMessage, topic);

            logger.trace("Response from FCM topic request: {}", result);
        }
    } else {
        logger.info(String.format("Sent push notification to FCM Server for %d registrationIDs", pushTargets.size()));
        MulticastResult multicastResult = sender.sendNoRetry(fcmMessage, pushTargets);

        logger.trace("Response from FCM request: {}", multicastResult);

        // after sending, let's identify the inactive/invalid registrationIDs and trigger their deletion:
        cleanupInvalidRegistrationIDsForVariant(androidVariant.getVariantID(), multicastResult, pushTargets);
    }
}
 
开发者ID:aerogear,项目名称:aerogear-unifiedpush-server,代码行数:28,代码来源:FCMPushNotificationSender.java

示例4: createGoogleNotifierWithBadAPIKey

import com.google.android.gcm.server.Constants; //导入依赖的package包/类
@Test
public void createGoogleNotifierWithBadAPIKey() throws Exception {

    final String badKey = API_KEY + "bad";

    // create notifier with bad API key
    app.clear();
    app.put("name", "gcm_bad_key");
    app.put("provider", PROVIDER);
    app.put("environment", "development");
    app.put("apiKey", badKey);

    try {
        notifier = (Notifier) app
            .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
            .toTypedEntity();
    } catch (InvalidRequestException e) {
        assertEquals(Constants.ERROR_INVALID_REGISTRATION, e.getDescription());
    }

}
 
开发者ID:apache,项目名称:usergrid,代码行数:22,代码来源:NotificationsServiceIT.java

示例5: sendMessage

import com.google.android.gcm.server.Constants; //导入依赖的package包/类
/**
 * Send to the first 10 devices (You can modify this to send to any number of devices or a specific device)
 *
 * @param message The message to send
 */
public void sendMessage(@Named("message") String message) throws IOException {
    if(message == null || message.trim().length() == 0) {
        log.warning("Not sending message because it is empty");
        return;
    }
    // crop longer messages
    if (message.length() > 1000) {
        message = message.substring(0, 1000) + "[...]";
    }
    Sender sender = new Sender(API_KEY);
    Message msg = new Message.Builder().addData("message", message).build();
    List<RegistrationRecord> records = ofy().load().type(RegistrationRecord.class).limit(10).list();
    for(RegistrationRecord record : records) {
        Result result = sender.send(msg, record.getRegId(), 5);
        if (result.getMessageId() != null) {
            log.info("Message sent to " + record.getRegId());
            String canonicalRegId = result.getCanonicalRegistrationId();
            if (canonicalRegId != null) {
                // if the regId changed, we have to update the datastore
                log.info("Registration Id changed for " + record.getRegId() + " updating to " + canonicalRegId);
                record.setRegId(canonicalRegId);
                ofy().save().entity(record).now();
            }
        } else {
            String error = result.getErrorCodeName();
            if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
                log.warning("Registration Id " + record.getRegId() + " no longer registered with GCM, removing from datastore");
                // if the device is no longer registered with Gcm, remove it from the datastore
                ofy().delete().entity(record).now();
            }
            else {
                log.warning("Error when sending message : " + error);
            }
        }
    }
}
 
开发者ID:scarrupt,项目名称:Capstone-Project,代码行数:42,代码来源:MessagingEndpoint.java

示例6: sendMessage

import com.google.android.gcm.server.Constants; //导入依赖的package包/类
/**
 * Send to the first 10 devices (You can modify this to send to any number of devices or a specific device)
 *
 * @param message The message to send
 */
public void sendMessage(@Named("message") String message) throws IOException {
    if (message == null || message.trim().length() == 0) {
        log.warning("Not sending message because it is empty");
        return;
    }
    // crop longer messages
    if (message.length() > 1000) {
        message = message.substring(0, 1000) + "[...]";
    }
    Sender sender = new Sender(API_KEY);
    Message msg = new Message.Builder().addData("message", message).build();
    List<RegistrationRecord> records = ofy().load().type(RegistrationRecord.class).limit(10).list();
    for (RegistrationRecord record : records) {
        Result result = sender.send(msg, record.getRegId(), 5);
        if (result.getMessageId() != null) {
            log.info("Message sent to " + record.getRegId());
            String canonicalRegId = result.getCanonicalRegistrationId();
            if (canonicalRegId != null) {
                // if the regId changed, we have to update the datastore
                log.info("Registration Id changed for " + record.getRegId() + " updating to " + canonicalRegId);
                record.setRegId(canonicalRegId);
                ofy().save().entity(record).now();
            }
        } else {
            String error = result.getErrorCodeName();
            if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
                log.warning("Registration Id " + record.getRegId() + " no longer registered with GCM, removing from datastore");
                // if the device is no longer registered with Gcm, remove it from the datastore
                ofy().delete().entity(record).now();
            } else {
                log.warning("Error when sending message : " + error);
            }
        }
    }
}
 
开发者ID:JimSeker,项目名称:googleplayAPI,代码行数:41,代码来源:MessagingEndpoint.java

示例7: sendGcmMessage

import com.google.android.gcm.server.Constants; //导入依赖的package包/类
@Override
public void sendGcmMessage(UserRecord user, Message message) throws IOException {
    boolean updateUser = false;
    // Use iterator instead of foreach to prevent ConcurrentModificationException
    ListIterator<String> iterator = user.getDevices().listIterator();
    while (iterator.hasNext()) {
        String device = iterator.next();
        Result result = sender.send(message, device, 1);
        if (result.getMessageId() != null) {
            String canonicalRegId = result.getCanonicalRegistrationId();
            if (canonicalRegId != null) {
                // if the regId changed, we have to update it
                iterator.remove();
                iterator.add(canonicalRegId);
                updateUser = true;
            }
        } else {
            String error = result.getErrorCodeName();
            if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
                // if the device is no longer registered with Gcm, remove it
                iterator.remove();
                updateUser = true;
            }
        }
    }
    if (updateUser) {
        userDAO.save(user);
    }
}
 
开发者ID:AndrewJack,项目名称:moment-for-android-wear,代码行数:30,代码来源:MomentGcmHelper.java

示例8: sendMessage

import com.google.android.gcm.server.Constants; //导入依赖的package包/类
/**
 * Send to the first 10 devices (You can modify this to send to any number of devices or a specific device)
 *
 * @param message The message to send
 */
public void sendMessage(@Named("message") String message) throws IOException {
    if (message == null || message.trim().length() == 0) {
        log.warning("Not sending message because it is empty");
        return;
    }
    // crop longer messages
    if (message.length() > 1000) {
        message = message.substring(0, 1000) + "[...]";
    }
    Sender sender = new Sender(API_KEY);
    Message msg = new Message.Builder().addData("message", message).build();
    List<RegistrationRecord> records = ofy().load().type(RegistrationRecord.class).limit(10).list();
    for (RegistrationRecord record : records) {
        Result result = sender.send(msg, record.getToken(), 5);
        if (result.getMessageId() != null) {
            log.info("Message sent to " + record.getToken());
            String canonicalRegId = result.getCanonicalRegistrationId();
            if (canonicalRegId != null) {
                // if the regId changed, we have to update the datastore
                log.info("Registration Id changed for " + record.getToken() + " updating to " + canonicalRegId);
                record.setToken(canonicalRegId);
                ofy().save().entity(record).now();
            }
        } else {
            String error = result.getErrorCodeName();
            if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
                log.warning("Registration Id " + record.getToken() + " no longer registered with GCM, removing from datastore");
                // if the device is no longer registered with Gcm, remove it from the datastore
                ofy().delete().entity(record).now();
            } else {
                log.warning("Error when sending message : " + error);
            }
        }
    }
}
 
开发者ID:tjyu1040,项目名称:GallyShuttle,代码行数:41,代码来源:MessagingEndpoint.java

示例9: sendMessage

import com.google.android.gcm.server.Constants; //导入依赖的package包/类
/**
 * Send to the first 10 devices
 *
 * @param message The message to send
 */
public void sendMessage(@Named("message") String message) throws IOException {
    if(message == null || message.trim().length() == 0) {
        log.warning("Not sending message because it is empty");
        return;
    }
    // crop longer messages
    if (message.length() > 1000) {
        message = message.substring(0, 1000) + "[...]";
    }
    Sender sender = new Sender(API_KEY);
    Message msg = new Message.Builder().addData("message", message).build();
    List<RegistrationRecord> records =
            ofy().load().type(RegistrationRecord.class).limit(10).list();
    for(RegistrationRecord record : records) {
        Result result = sender.send(msg, record.getRegId(), 5);
        if (result.getMessageId() != null) {
            log.info("Message sent to " + record.getRegId());
            String canonicalRegId = result.getCanonicalRegistrationId();
            if (canonicalRegId != null) {
                // if the regId changed, we have to update the datastore
                log.info("Registration Id changed for " + record.getRegId()
                        + " updating to " + canonicalRegId);
                record.setRegId(canonicalRegId);
                ofy().save().entity(record).now();
            }
        } else {
            String error = result.getErrorCodeName();
            if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
                log.warning("Registration Id " + record.getRegId()
                        + " no longer registered with GCM, removing from datastore");
                // if the device is no longer registered with Gcm, remove it from the datastore
                ofy().delete().entity(record).now();
            }
            else {
                log.warning("Error when sending message : " + error);
            }
        }
    }
}
 
开发者ID:vaektor,项目名称:Loqale,代码行数:45,代码来源:MessagingEndpoint.java

示例10: doSendViaGcm

import com.google.android.gcm.server.Constants; //导入依赖的package包/类
/**
 * Sends the message using the Sender object to the registered device.
 * 
 * @param message
 *            the message to be sent in the GCM ping to the device.
 * @param sender
 *            the Sender object to be used for ping,
 * @param deviceInfo
 *            the registration id of the device.
 * @return Result the result of the ping.
 */
private static Result doSendViaGcm(String message, Sender sender,
		DBObject deviceInfo, DBCollection coll) throws IOException {
	// Trim message if needed.
	if (message.length() > 1000) {
		message = message.substring(0, 1000) + "[...]";
	}

	// This message object is a Google Cloud Messaging object, it is NOT 
	// related to the MessageData class
	Message msg = new Message.Builder().addData("message", message).build();
	Result result = sender.send(msg, (String) deviceInfo.get("_id"),
			5);
	if (result.getMessageId() != null) {
		String canonicalRegId = result.getCanonicalRegistrationId();
		if (canonicalRegId != null) {
			// same device has more than on registration ID: update database
			coll.save(deviceInfo);
		}
	} else {
		String error = result.getErrorCodeName();
		if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
			// application has been removed from device - unregister database
			coll.remove(deviceInfo);
		}
	}

	return result;
}
 
开发者ID:johan12345,项目名称:vertretungsplan-server,代码行数:40,代码来源:ParseThread.java

示例11: sendGcmNotification

import com.google.android.gcm.server.Constants; //导入依赖的package包/类
void sendGcmNotification(final PatientEntity p, final String title, final String msg) {
	if (!p.isGcmUser()) {
		throw new IllegalStateException(
				"User is not an Android user. We should never attempt to send a GCM message if we don't have a valid GCM registration id");
	}

	final String regId = p.getProperties().get("c2dmRegistrationId");

	try {
		Sender sender = new Sender(this.gcmAuthKey);
		Message message = new Message.Builder().addData("title", title).addData("message", msg)
				.addData("timestamp", String.valueOf(System.currentTimeMillis())).build();

		Result result = sender.send(message, regId, 5);

		if (result.getMessageId() != null) {
			String canonicalRegId = result.getCanonicalRegistrationId();
			if (canonicalRegId != null) {
				// same device has more than on registration ID: update
				// database
				getLog().debug(
						"Google indicates that the device has more than one registration id. Update to the correct one");
				p.getProperties().put("c2dmRegistrationId", canonicalRegId);
			}
		} else {
			String error = result.getErrorCodeName();

			if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
				// application has been removed from device - unregister
				// database
				getLog().debug(
						"Google indicates that the registration id has been removed from the device. Remove from our database.");
				p.getProperties().remove("c2dmRegistrationId");
			}
		}
	} catch (final IOException e) {
		e.printStackTrace();
		getLog().warn("Could not send push through the GCM network. Error was: " + e.getMessage());
	}
}
 
开发者ID:MinHalsoplan,项目名称:netcare-healthplan,代码行数:41,代码来源:PushNotificationServiceImpl.java

示例12: push

import com.google.android.gcm.server.Constants; //导入依赖的package包/类
public final void push(String registrationId, String apiKey,
		Map<String, Object> args, boolean delayWhileIdle)
		throws IOException {
	Sender sender = new Sender(apiKey);
	Message.Builder builder = new Message.Builder();
	builder.timeToLive(60 * 60).collapseKey("MAGIC_STRING")
			.delayWhileIdle(delayWhileIdle);
	for (String key : args.keySet()) {
		builder.addData(key, "" + args.get(key));
	}
	Message message = builder.build();
	Result result = sender.send(message, registrationId, 5);
	if (result.getMessageId() != null) {
		String canonicalRegId = result.getCanonicalRegistrationId();
		if (canonicalRegId != null) {
			// same device has more than on registration ID: update database
			System.out
					.println("same device has more than on registration ID: update database");
		} else {
			System.out.println("ok");
		}
	} else {
		String error = result.getErrorCodeName();
		if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
			// application has been removed from device - unregister
			// database
			System.out
					.println("application has been removed from device - unregister database");
		}
		System.out.println("ok 2: " + error);
	}
}
 
开发者ID:interdroid,项目名称:cuckoo-library,代码行数:33,代码来源:RemoteMonitorThread.java

示例13: sendSingleMessage

import com.google.android.gcm.server.Constants; //导入依赖的package包/类
private void sendSingleMessage(String regId, HttpServletResponse resp) {
  logger.info("Sending message to device " + regId);
  Message message = createMessage();
  Result result;
  try {
    result = sender.sendNoRetry(message, regId);
  } catch (IOException e) {
    logger.log(Level.SEVERE, "Exception posting " + message, e);
    taskDone(resp);
    return;
  }
  if (result == null) {
    retryTask(resp);
    return;
  }
  if (result.getMessageId() != null) {
    logger.info("Succesfully sent message to device " + regId);
    String canonicalRegId = result.getCanonicalRegistrationId();
    if (canonicalRegId != null) {
      // same device has more than on registration id: update it
      logger.finest("canonicalRegId " + canonicalRegId);
      Datastore.updateRegistration(regId, canonicalRegId);
    }
  } else {
    String error = result.getErrorCodeName();
    if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
      // application has been removed from device - unregister it
      Datastore.unregister(regId);
    } else {
      logger.severe("Error sending message to device " + regId
          + ": " + error);
    }
  }
}
 
开发者ID:army-of-dumbledore,项目名称:pennappsF13,代码行数:35,代码来源:SendMessageServlet.java

示例14: doSendViaGcm

import com.google.android.gcm.server.Constants; //导入依赖的package包/类
private static Result doSendViaGcm(String message, Sender sender,
                                   DeviceInfo deviceInfo) throws IOException {
    // Trim message if needed.
    if (message.length() > 1000) {
        message = message.substring(0, 1000) + "[...]";
    }

    // This message object is a Google Cloud Messaging object, it is NOT
    // related to the MessageData class
    Message msg = new Message.Builder().addData("message", message).build();
    Result result = sender.send(msg, deviceInfo.getDeviceRegistrationID(),
            5);
    if (result.getMessageId() != null) {
        String canonicalRegId = result.getCanonicalRegistrationId();
        if (canonicalRegId != null) {
            endpoint.removeDeviceInfo(deviceInfo.getDeviceRegistrationID());
            deviceInfo.setDeviceRegistrationID(canonicalRegId);
            endpoint.insertDeviceInfo(null, deviceInfo);
        }
    } else {
        String error = result.getErrorCodeName();
        if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
            endpoint.removeDeviceInfo(deviceInfo.getDeviceRegistrationID());
        }
    }

    return result;
}
 
开发者ID:gabuzomeu,项目名称:geoPingProject,代码行数:29,代码来源:StopWatchStateEndpoint.java

示例15: doSendViaGcm

import com.google.android.gcm.server.Constants; //导入依赖的package包/类
/**
 * Sends the message using the Sender object to the registered device.
 *
 * @param message    the message to be sent in the GCM ping to the device.
 * @param sender     the Sender object to be used for ping,
 * @param deviceInfo the registration id of the device.
 * @return Result the result of the ping.
 */
private static Result doSendViaGcm(String message, Sender sender,
                                   DeviceInfo deviceInfo) throws IOException {
    // Trim message if needed.
    if (message.length() > 1000) {
        message = message.substring(0, 1000) + "[...]";
    }

    // This message object is a Google Cloud Messaging object, it is NOT 
    // related to the MessageData class
    Message msg = new Message.Builder().addData("message", message).build();
    Result result = sender.send(msg, deviceInfo.getDeviceRegistrationID(),
            5);
    if (result.getMessageId() != null) {
        String canonicalRegId = result.getCanonicalRegistrationId();
        if (canonicalRegId != null) {
            endpoint.removeDeviceInfo(deviceInfo.getDeviceRegistrationID());
            deviceInfo.setDeviceRegistrationID(canonicalRegId);
            endpoint.insertDeviceInfo(null, deviceInfo);
        }
    } else {
        String error = result.getErrorCodeName();
        if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
            endpoint.removeDeviceInfo(deviceInfo.getDeviceRegistrationID());
        }
    }

    return result;
}
 
开发者ID:gabuzomeu,项目名称:geoPingProject,代码行数:37,代码来源:MessageEndpoint.java


注:本文中的com.google.android.gcm.server.Constants类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。