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


Java Result类代码示例

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


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

示例1: sendMessage

import com.google.android.gcm.server.Result; //导入依赖的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: sendNotifications

import com.google.android.gcm.server.Result; //导入依赖的package包/类
public Result sendNotifications(String msg, String listUser) {
    Result result = null;
    String[] users = listUser.split(",");
    try {
        for (int i = 0; i < users.length; i++) {
            String deviceId = userDAO.getDeviceId(users[i]);

            Sender sender = new Sender(GOOGLE_SERVER_KEY);
            Message message = new Message.Builder().timeToLive(120)
                    .delayWhileIdle(false).addData(MESSAGE_KEY, msg).build();
            System.out.println("User: " + users[i] + " - regId: " + deviceId);
            result = sender.send(message, deviceId, 1);
        }
       return result;
    } catch (IOException ioe) {
        ioe.printStackTrace();

    } catch (Exception e) {
        e.printStackTrace();

    }
    return result;
}
 
开发者ID:tranquang9a1,项目名称:ECRM,代码行数:24,代码来源:GCMService.java

示例3: sendNotification

import com.google.android.gcm.server.Result; //导入依赖的package包/类
public void sendNotification(String msg, String deviceId) {
    System.out.println("Start send notification" + deviceId);
    Result result = null;
    try {

        Sender sender = new Sender(GOOGLE_SERVER_KEY);
        Message message = new Message.Builder().timeToLive(120)
                .delayWhileIdle(false).addData(MESSAGE_KEY, msg).build();
        result = sender.send(message, deviceId, 1);
        System.out.println("Send Notification Success: " + result.toString());
        System.out.println("RegID: " + deviceId);
        System.out.println("End send notification");
    } catch (IOException ioe) {
        ioe.printStackTrace();
        System.out.println("Error when send notification " + ioe.toString());
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Error when send notification " + e.toString());
    }
}
 
开发者ID:tranquang9a1,项目名称:ECRM,代码行数:21,代码来源:GCMService.java

示例4: sendNotification

import com.google.android.gcm.server.Result; //导入依赖的package包/类
@POST
	@Path("/sendNotification/user/{account}")
	public String sendNotification(@HeaderParam("Authorization") String token, String text, 
			@PathParam("account") String account,
			@DefaultValue("application/json") @HeaderParam("Content-Type") String contentType,
			@DefaultValue("application/json") @HeaderParam("Accept") String accept)  {
		if (!validCredentials(token))
			return serialise(getInvalidCredentialsBean(), accept);
//		(new ApplePushNotificationDelegator(token)).sendNotification(account, text);
		Sender sender = new Sender("AIzaSyBBHzixGmnJnu8YhZS44zCObl85JTspo_Q");
		Message message = new Message.Builder().addData("runId", "1234").build();
		
		try {
			Result result = sender.send(message, "APA91bFDiScakJJnxA9LfFNknB965TdghV5ep7w5ZGwOG51JJF_X3MBy3_set6mPPaYRK_ceWcK00JF9x6vW-vuDGB4dYqgevukafBYq8VgovwG8dyLK4QtbT123N_8_hmACIJ185JztOBvVLb-8AlDLJPG_I3gldQ", 5);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "sent";
	}
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:21,代码来源:GoogleCloadMessaging.java

示例5: sendGCMNotificationAsJson

import com.google.android.gcm.server.Result; //导入依赖的package包/类
public void sendGCMNotificationAsJson(String account, String registrationId, HashMap<String, Object> valueMap, String packageIdentifier) {
        if (packageIdentifier == null || "".equals(packageIdentifier)) return;
//        log.log(Level.WARNING, "gcm key " + ConfigurationManager.getValue(GCM_KEY+packageIdentifier));
//        log.log(Level.WARNING, "packageIdentifier " + packageIdentifier);
//        log.log(Level.WARNING, "regId " + registrationId);
        Sender sender = new Sender(ConfigurationManager.getValue(GCM_KEY+packageIdentifier));
        Message.Builder builder = new Message.Builder();
        for (Map.Entry<String, Object> entry : valueMap.entrySet()) {
            builder.addData(entry.getKey(), "" + entry.getValue());
        }
        Message message = builder.build();
        try {
            Result result = sender.send(message, registrationId, 5);
            log.log(Level.WARNING, "sent " + message.toString());
            log.log(Level.WARNING, "result " + result);
        } catch (IOException e) {
            log.log(Level.SEVERE, "errr", e);
            e.printStackTrace();
        }
    }
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:21,代码来源:NotificationDelegator.java

示例6: sendGcmAlert

import com.google.android.gcm.server.Result; //导入依赖的package包/类
private void sendGcmAlert(String subId, String regId)
    throws IOException {
  String gcmKey = backendConfigManager.getGcmKey();
  boolean isGcmKeySet = !(gcmKey == null || gcmKey.trim().length() == 0);

  // Only attempt to send GCM if GcmKey is available
  if (isGcmKeySet) {
    Sender sender = new Sender(gcmKey);
    Message message = new Message.Builder().addData(SubscriptionUtility.GCM_KEY_SUBID, subId)
        .build();
    Result r = sender.send(message, regId, GCM_SEND_RETRIES);
    if (r.getMessageId() != null) {
      log.info("ProspectiveSearchServlet: GCM sent: subId: " + subId);
    } else {
      log.warning("ProspectiveSearchServlet: GCM error for subId: " + subId +
          ", senderId: " + gcmKey + ", error: " + r.getErrorCodeName());
      ArrayList<String> deviceIds = new ArrayList<String>();
      deviceIds.add(regId);
      SubscriptionUtility.clearSubscriptionAndDeviceEntity(deviceIds);
    }
  } else {
    // Otherwise, just write a log entry
    log.info(String.format("ProspectiveSearchServlet: GCM is not sent: GcmKey: %s ", 
        isGcmKeySet));
  }
}
 
开发者ID:googlesamples,项目名称:io2014-codelabs,代码行数:27,代码来源:ProspectiveSearchServlet.java

示例7: processFCM

import com.google.android.gcm.server.Result; //导入依赖的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

示例8: requestSubscription

import com.google.android.gcm.server.Result; //导入依赖的package包/类
public static void requestSubscription(long id, String subUsername, String pubGcmToken) throws IOException {
			
	Sender sender = new Sender(API_KEY);
	Message msg = new Message.Builder()
			.addData(MESSAGE_TYPE, SUBSCRIPTION_REQUEST)
			.addData(SUBSCRIBER_ID, id + "")
			.addData(SUBSCRIBER_USERNAME, subUsername)
			.build();
	Result result = sender.send(msg, pubGcmToken, 1);
	System.out.println(msg.toString());
	System.out.println(result.toString());		
}
 
开发者ID:kflauri2312lffds,项目名称:Android_watch_magpie,代码行数:13,代码来源:GcmSender.java

示例9: sendNotification

import com.google.android.gcm.server.Result; //导入依赖的package包/类
/**
 * sendNotification
 * sends an android notification to and android device through google
 *   cloud messaging server
 * @param androidNotification
 * @return Result or NULL in case of failure
 * @throws Exception
 * consumes Exceptions since notifications's failure are generally a
 *   low-business impact that shouldn't stop processing the rest of
 *   the request
 */
public Result sendNotification (
  AndroidNotification androidNotification) throws Exception {
  
  try {
    
    return this.sender.send(
      androidNotification.getMessage(),
      androidNotification.getTo(),
      androidNotification.getRetries() );
  } catch (Exception e) {
    
    return null;
  }
}
 
开发者ID:vangav,项目名称:vos_backend,代码行数:26,代码来源:AndroidNotificationSender.java

示例10: sendMessage

import com.google.android.gcm.server.Result; //导入依赖的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

示例11: run

import com.google.android.gcm.server.Result; //导入依赖的package包/类
public void run() {
	Sender sender = new Sender(SENDER_ID);

	Message message = new Message.Builder()
			// If multiple messages are sent while device is offline,
			// only receive the latest message is received.
			.collapseKey(COLLAPSE_KEY + "_" + p.getId())
			// TTL = 6 hours (if scheduled at 9h, push is received until
			// 15h)
			.timeToLive(21600).delayWhileIdle(true).addData("title", p.getTitle())
			.addData("numberOfRestaurants", restaurantsForPushCount.toString())
			.addData("longitude", String.valueOf(p.getLongitude()))
			.addData("latitude", String.valueOf(p.getLatitude())).addData("radius", String.valueOf(p.getRadius()))
			.addData("kitchenTypeIds", pushKitchenTypeIds.toString()).addData("pushId", String.valueOf(p.getId()))
			.build();

	try {

		Result result = sender.send(message, p.getGcmToken(), NUMBER_OF_RETRIES);

		if (result.getErrorCodeName() == null) {
			LOGGER.info(
					LogUtils.getDefaultSchedulerMessage(Thread.currentThread().getStackTrace()[1].getMethodName(),
							"GCM Notification was sent successfully: " + message.toString()));
		} else if (result.getErrorCodeName().equals("InvalidRegistration")) {
			pushRepo.delete(p);
			LOGGER.error(LogUtils.getErrorMessage(Thread.currentThread().getStackTrace()[1].getMethodName(),
					"GCM Token invalid: Push-Notification is deleted."));
		} else {
			LOGGER.error(LogUtils.getErrorMessage(Thread.currentThread().getStackTrace()[1].getMethodName(),
					"Error occurred while sending push notification :" + result.getErrorCodeName()));
		}

	} catch (Exception e) {
		LOGGER.error(LogUtils.getExceptionMessage(Thread.currentThread().getStackTrace()[1].getMethodName(), e));
	}

	return;
}
 
开发者ID:andju,项目名称:findlunch,代码行数:40,代码来源:PushNotificationScheduledTask.java

示例12: sendMessage

import com.google.android.gcm.server.Result; //导入依赖的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

示例13: sendGcmMessage

import com.google.android.gcm.server.Result; //导入依赖的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

示例14: sendNotification

import com.google.android.gcm.server.Result; //导入依赖的package包/类
@RequestMapping(value = "/sendNotification")
public ResultDTO sendNotification(@RequestParam("message") String msg, HttpServletRequest request,
                                  @RequestParam("ListUser") String listUser) {

    try {
        Result result = gcmService.sendNotifications(msg, listUser);
        return new ResultDTO(200, result.toString());
    } catch (Exception e) {
        return new ResultDTO(500, e.getMessage());
    }


}
 
开发者ID:tranquang9a1,项目名称:ECRM,代码行数:14,代码来源:GCMController.java

示例15: sendMessage

import com.google.android.gcm.server.Result; //导入依赖的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


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