com.easemob.util.EasyUtils Java Examples

The following examples show how to use com.easemob.util.EasyUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EaseNotifier.java    From monolog-android with MIT License 6 votes vote down vote up
/**
 * 处理新收到的消息,然后发送通知
 * 
 * 开发者可以重载此函数
 * this function can be override
 * 
 * @param message
 */
public synchronized void onNewMsg(EMMessage message) {
    if(EMChatManager.getInstance().isSlientMessage(message)){
        return;
    }
    EaseSettingsProvider settingsProvider = EaseUI.getInstance().getSettingsProvider();
    if(!settingsProvider.isMsgNotifyAllowed(message)){
        return;
    }
    
    // 判断app是否在后台
    if (!EasyUtils.isAppRunningForeground(appContext)) {
        EMLog.d(TAG, "app is running in backgroud");
        sendNotification(message, false);
    } else {
        sendNotification(message, true);

    }
    
    viberateAndPlayTone(message);
}
 
Example #2
Source File: EaseNotifier.java    From monolog-android with MIT License 6 votes vote down vote up
public synchronized void onNewMesg(List<EMMessage> messages) {
    if(EMChatManager.getInstance().isSlientMessage(messages.get(messages.size()-1))){
        return;
    }
    EaseSettingsProvider settingsProvider = EaseUI.getInstance().getSettingsProvider();
    if(!settingsProvider.isMsgNotifyAllowed(null)){
        return;
    }
    // 判断app是否在后台
    if (!EasyUtils.isAppRunningForeground(appContext)) {
        EMLog.d(TAG, "app is running in backgroud");
        sendNotification(messages, false);
    } else {
        sendNotification(messages, true);
    }
    viberateAndPlayTone(messages.get(messages.size()-1));
}
 
Example #3
Source File: HXNotifier.java    From school_shop with MIT License 6 votes vote down vote up
/**
 * 处理新收到的消息,然后发送通知
 * 
 * 开发者可以重载此函数
 * this function can be override
 * 
 * @param message
 */
public synchronized void onNewMsg(final EMMessage message) {
    if(EMChatManager.getInstance().isSlientMessage(message)){
        return;
    }
    
    // 判断app是否在后台
    if (!EasyUtils.isAppRunningForeground(appContext)) {
        EMLog.d(TAG, "app is running in backgroud");
        sendNotification(message, false);
    } else {
        sendNotification(message, true);

    }
    
    viberateAndPlayTone(message);
}
 
Example #4
Source File: BaseActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 当应用在前台时,如果当前消息不是属于当前会话,在状态栏提示一下 如果不需要,注释掉即可
 * 
 * @param message
 */
protected void notifyNewMessage(EMMessage message) {
    // 如果是设置了不提醒只显示数目的群组(这个是app里保存这个数据的,demo里不做判断)
    // 以及设置了setShowNotificationInbackgroup:false(设为false后,后台时sdk也发送广播)
    if (!EasyUtils.isAppRunningForeground(this)) {
        return;
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
            this).setSmallIcon(getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis()).setAutoCancel(true);

    String ticker = CommonUtils.getMessageDigest(message, this);
    if (message.getType() == Type.TXT)
        ticker = ticker.replaceAll("\\[.{2,3}\\]", "[表情]");
    // 设置状态栏提示
    mBuilder.setTicker(message.getFrom() + ": " + ticker);

    // 必须设置pendingintent,否则在2.3的机器上会有bug
    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, notifiId,
            intent, PendingIntent.FLAG_ONE_SHOT);
    mBuilder.setContentIntent(pendingIntent);

    Notification notification = mBuilder.build();
    notificationManager.notify(notifiId, notification);
    notificationManager.cancel(notifiId);
}
 
Example #5
Source File: DemoHXSDKHelper.java    From school_shop with MIT License 5 votes vote down vote up
@Override
public HXNotifier createNotifier(){
    return new HXNotifier(){
        public synchronized void onNewMsg(final EMMessage message) {
            if(EMChatManager.getInstance().isSlientMessage(message)){
                return;
            }
            
            String chatUsename = null;
            List<String> notNotifyIds = null;
            // 获取设置的不提示新消息的用户或者群组ids
            if (message.getChatType() == ChatType.Chat) {
                chatUsename = message.getFrom();
                notNotifyIds = ((DemoHXSDKModel) hxModel).getDisabledGroups();
            } else {
                chatUsename = message.getTo();
                notNotifyIds = ((DemoHXSDKModel) hxModel).getDisabledIds();
            }

            if (notNotifyIds == null || !notNotifyIds.contains(chatUsename)) {
                // 判断app是否在后台
                if (!EasyUtils.isAppRunningForeground(appContext)) {
                    EMLog.d(TAG, "app is running in backgroud");
                    sendNotification(message, false);
                } else {
                    sendNotification(message, true);

                }
                
                viberateAndPlayTone(message);
            }
        }
    };
}