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


Java EMChat类代码示例

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


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

示例1: loadLoginData

import com.easemob.chat.EMChat; //导入依赖的package包/类
/**
     * 处理登陆数据
     *
     * @param resposne
     */
    private void loadLoginData(CommonResponse resposne) {
//        if (resposne.isSuccess()) {
        SharedPreferencesHelper.setString(this, Constant.LoginUser.SHARED_PREFERENCES_PHONE, phone);
        SharedPreferencesHelper.setString(this, Constant.LoginUser.SHARED_PREFERENCES_PASSWORD, password);
        UserInfo userInfo = UserInfo.testData();
        String userJson = JSON.toJSONString(userInfo);
        SharedPreferencesHelper.setString(this, Constant.LoginUser.SHARED_PREFERENCES_USER, userJson);
        App.getInstance().setgUserInfo(userInfo);
        if (!EMChat.getInstance().isLoggedIn()) {
            EASEMOBLogin();
        } else {
            dialogDismiss();
            EMGroupManager.getInstance().loadAllGroups();
            EMChatManager.getInstance().loadAllConversations();
            toMainActivity();
        }
//        } else {
//            dialogDismiss();
//            CommonUtil.showToast(resposne.getErrorTip());
//        }
    }
 
开发者ID:tengbinlive,项目名称:info_demo,代码行数:27,代码来源:LoginActivity.java

示例2: init

import com.easemob.chat.EMChat; //导入依赖的package包/类
/**
 * init helper
 *
 * @param context application context
 */
public void init(Context context) {
    if (EaseUI.getInstance().init(context)) {
        appContext = context;
        //设为调试模式,打成正式包时,最好设为false,以免消耗额外的资源
        EMChat.getInstance().setDebugMode(true);
        //get easeui instance
        easeUI = EaseUI.getInstance();
        //调用easeui的api设置providers
        setEaseUIProviders();
        demoModel = new DemoModel(context);
        //设置chat options
        setChatoptions();
        //初始化PreferenceManager
        PreferenceManager.init(context);
        //初始化用户管理类
        getUserProfileManager().init(context);

        //设置全局监听
        setGlobalListeners();
        broadcastManager = LocalBroadcastManager.getInstance(appContext);
        initDbDao();
    }
}
 
开发者ID:nggirl,项目名称:EaseChatDemo,代码行数:29,代码来源:DemoHelper.java

示例3: init

import com.easemob.chat.EMChat; //导入依赖的package包/类
/**
 *this function will initialize the HuanXin SDK
 * 
 * @return boolean true if caller can continue to call HuanXin related APIs after calling onInit, otherwise false.
 * 
 * 初始化环信sdk及easeui库
 * 返回true如果正确初始化,否则false,如果返回为false,请在后续的调用中不要调用任何和环信相关的代码
 * @param context
 * @return
 */
public synchronized boolean init(Context context){
    if(sdkInited){
        return true;
    }
    appContext = context;
    
    int pid = android.os.Process.myPid();
    String processAppName = getAppName(pid);
    
    Log.d(TAG, "process app name : " + processAppName);
    
    // 如果app启用了远程的service,此application:onCreate会被调用2次
    // 为了防止环信SDK被初始化2次,加此判断会保证SDK被初始化1次
    // 默认的app会在以包名为默认的process name下运行,如果查到的process name不是app的process name就立即返回
    if (processAppName == null || !processAppName.equalsIgnoreCase(appContext.getPackageName())) {
        Log.e(TAG, "enter the service process!");
        
        // 则此application::onCreate 是被service 调用的,直接返回
        return false;
    }
    // 初始化环信SDK,一定要先调用init()
    EMChat.getInstance().init(context);
    initChatOptions();
    if(settingsProvider == null){
        settingsProvider = new DefaultSettingsProvider();
    }
    
    sdkInited = true;
    return true;
}
 
开发者ID:huijimuhe,项目名称:monolog-android,代码行数:41,代码来源:EaseUI.java

示例4: init

import com.easemob.chat.EMChat; //导入依赖的package包/类
/**
 * init helper
 * 
 * @param context
 *            application context
 */
public void init(Context context) {
	if (EaseUI.getInstance().init(context)) {
	    appContext = context;
	    
	    //if your app is supposed to user Google Push, please set project number
           String projectNumber = "562451699741";
           //不使用GCM推送的注释掉这行
           EMChatManager.getInstance().setGCMProjectNumber(projectNumber);
           //在小米手机上当app被kill时使用小米推送进行消息提示,同GCM一样不是必须的
           EMChatManager.getInstance().setMipushConfig("2882303761517370134", "5131737040134");
	    
	    //设为调试模式,打成正式包时,最好设为false,以免消耗额外的资源
	    EMChat.getInstance().setDebugMode(true);
	    //get easeui instance
	    easeUI = EaseUI.getInstance();
	    //调用easeui的api设置providers
	    setEaseUIProviders();
	    demoModel = new DemoModel(context);
	    //设置chat options
	    setChatoptions();
		//初始化PreferenceManager
		PreferenceManager.init(context);
		//初始化用户管理类
		getUserProfileManager().init(context);
		
		//设置全局监听
		setGlobalListeners();
		broadcastManager = LocalBroadcastManager.getInstance(appContext);
        initDbDao();
        
	}
}
 
开发者ID:easemob,项目名称:sdkdemoapp3.0_android,代码行数:39,代码来源:DemoHelper.java

示例5: notifyForRecevingEvents

import com.easemob.chat.EMChat; //导入依赖的package包/类
public synchronized void notifyForRecevingEvents(){
    if(alreadyNotified){
        return;
    }
    
    // 通知sdk,UI 已经初始化完毕,注册了相应的receiver和listener, 可以接受broadcast了
    EMChat.getInstance().setAppInited();
    alreadyNotified = true;
}
 
开发者ID:easemob,项目名称:sdkdemoapp3.0_android,代码行数:10,代码来源:DemoHelper.java

示例6: asyncFetchContactInfosFromServer

import com.easemob.chat.EMChat; //导入依赖的package包/类
public void asyncFetchContactInfosFromServer(List<String> usernames, final EMValueCallBack<List<EaseUser>> callback) {
	if (isSyncingContactInfosWithServer) {
		return;
	}
	isSyncingContactInfosWithServer = true;
	ParseManager.getInstance().getContactInfos(usernames, new EMValueCallBack<List<EaseUser>>() {

		@Override
		public void onSuccess(List<EaseUser> value) {
			isSyncingContactInfosWithServer = false;
			// in case that logout already before server returns,we should
			// return immediately
			if (!EMChat.getInstance().isLoggedIn()) {
				return;
			}
			if (callback != null) {
				callback.onSuccess(value);
			}
		}

		@Override
		public void onError(int error, String errorMsg) {
			isSyncingContactInfosWithServer = false;
			if (callback != null) {
				callback.onError(error, errorMsg);
			}
		}

	});

}
 
开发者ID:easemob,项目名称:sdkdemoapp3.0_android,代码行数:32,代码来源:UserProfileManager.java

示例7: init

import com.easemob.chat.EMChat; //导入依赖的package包/类
/**
 * this function will initialize the HuanXin SDK
 * 
 * @return boolean true if caller can continue to call HuanXin related APIs
 *         after calling onInit, otherwise false.
 * 
 *         初始化环信sdk及easeui库
 *         返回true如果正确初始化,否则false,如果返回为false,请在后续的调用中不要调用任何和环信相关的代码
 * @param context
 * @return
 */
public synchronized boolean init(Context context) {
	if (sdkInited) {
		return true;
	}
	appContext = context;

	int pid = android.os.Process.myPid();
	String processAppName = getAppName(pid);

	Log.d(TAG, "process app name : " + processAppName);

	// 如果app启用了远程的service,此application:onCreate会被调用2次
	// 为了防止环信SDK被初始化2次,加此判断会保证SDK被初始化1次
	// 默认的app会在以包名为默认的process name下运行,如果查到的process name不是app的process
	// name就立即返回
	if (processAppName == null || !processAppName.equalsIgnoreCase(appContext.getPackageName())) {
		Log.e(TAG, "enter the service process!");

		// 则此application::onCreate 是被service 调用的,直接返回
		return false;
	}
	// 初始化环信SDK,一定要先调用init()
	EMChat.getInstance().init(context);

	initChatOptions();
	if (settingsProvider == null) {
		settingsProvider = new DefaultSettingsProvider();
	}

	sdkInited = true;
	return true;
}
 
开发者ID:easemob,项目名称:easeui,代码行数:44,代码来源:EaseUI.java

示例8: asyncFetchGroupsFromServer

import com.easemob.chat.EMChat; //导入依赖的package包/类
/**
 * 同步操作,从服务器获取群组列表
 * 该方法会记录更新状态,可以通过isSyncingGroupsFromServer获取是否正在更新
 * 和HXPreferenceUtils.getInstance().getSettingSyncGroupsFinished()获取是否更新已经完成
 * @throws EaseMobException
 */
public synchronized void asyncFetchGroupsFromServer(final EMCallBack callback){
    if(isSyncingGroupsWithServer){
        return;
    }
    
    isSyncingGroupsWithServer = true;
    
    new Thread(){
        @Override
        public void run(){
            try {
                EMGroupManager.getInstance().getGroupsFromServer();
                
                // in case that logout already before server returns, we should return immediately
                if(!EMChat.getInstance().isLoggedIn()){
                    return;
                }
                
                hxModel.setGroupsSynced(true);
                
                isGroupsSyncedWithServer = true;
                isSyncingGroupsWithServer = false;
                if(callback != null){
                    callback.onSuccess();
                }
            } catch (EaseMobException e) {
                hxModel.setGroupsSynced(false);
                isGroupsSyncedWithServer = false;
                isSyncingGroupsWithServer = false;
                if(callback != null){
                    callback.onError(e.getErrorCode(), e.toString());
                }
            }
        
        }
    }.start();
}
 
开发者ID:chenjunqian,项目名称:here,代码行数:44,代码来源:HXSDKHelper.java

示例9: asyncFetchContactsFromServer

import com.easemob.chat.EMChat; //导入依赖的package包/类
public void asyncFetchContactsFromServer(final EMValueCallBack<List<String>> callback){
    if(isSyncingContactsWithServer){
        return;
    }
    
    isSyncingContactsWithServer = true;
    
    new Thread(){
        @Override
        public void run(){
            List<String> usernames = null;
            try {
                usernames = EMContactManager.getInstance().getContactUserNames();
                
                // in case that logout already before server returns, we should return immediately
                if(!EMChat.getInstance().isLoggedIn()){
                    return;
                }
                
                hxModel.setContactSynced(true);
                
                isContactsSyncedWithServer = true;
                isSyncingContactsWithServer = false;
                if(callback != null){
                    callback.onSuccess(usernames);
                }
            } catch (EaseMobException e) {
                hxModel.setContactSynced(false);
                isContactsSyncedWithServer = false;
                isSyncingContactsWithServer = false;
                e.printStackTrace();
                if(callback != null){
                    callback.onError(e.getErrorCode(), e.toString());
                }
            }
            
        }
    }.start();
}
 
开发者ID:chenjunqian,项目名称:here,代码行数:40,代码来源:HXSDKHelper.java

示例10: asyncFetchContactInfosFromServer

import com.easemob.chat.EMChat; //导入依赖的package包/类
public void asyncFetchContactInfosFromServer(List<String> usernames, final EMValueCallBack<List<EMUser>> callback) {
	if (isSyncingContactInfosWithServer) {
		return;
	}
	isSyncingContactInfosWithServer = true;
	ParseManager.getInstance().getContactInfos(usernames, new EMValueCallBack<List<EMUser>>() {

		@Override
		public void onSuccess(List<EMUser> value) {
			isSyncingContactInfosWithServer = false;
			// in case that logout already before server returns,we should
			// return immediately
			if (!EMChat.getInstance().isLoggedIn()) {
				return;
			}
			if (callback != null) {
				callback.onSuccess(value);
			}
		}

		@Override
		public void onError(int error, String errorMsg) {
			isSyncingContactInfosWithServer = false;
			if (callback != null) {
				callback.onError(error, errorMsg);
			}
		}

	});

}
 
开发者ID:chenjunqian,项目名称:here,代码行数:32,代码来源:UserProfileManager.java

示例11: notifyForRecevingEvents

import com.easemob.chat.EMChat; //导入依赖的package包/类
public synchronized void notifyForRecevingEvents() {
    if (alreadyNotified) {
        return;
    }

    // 通知sdk,UI 已经初始化完毕,注册了相应的receiver和listener, 可以接受broadcast了
    EMChat.getInstance().setAppInited();
    alreadyNotified = true;
}
 
开发者ID:nggirl,项目名称:EaseChatDemo,代码行数:10,代码来源:DemoHelper.java

示例12: asyncFetchContactInfosFromServer

import com.easemob.chat.EMChat; //导入依赖的package包/类
public void asyncFetchContactInfosFromServer(List<String> usernames, final EMValueCallBack<List<EaseUser>> callback) {
    if (isSyncingContactInfosWithServer) {
        return;
    }
    isSyncingContactInfosWithServer = true;
    ParseManager.getInstance().getContactInfos(usernames, new EMValueCallBack<List<EaseUser>>() {

        @Override
        public void onSuccess(List<EaseUser> value) {
            isSyncingContactInfosWithServer = false;
            // in case that logout already before server returns,we should
            // return immediately
            if (!EMChat.getInstance().isLoggedIn()) {
                return;
            }
            if (callback != null) {
                callback.onSuccess(value);
            }
        }

        @Override
        public void onError(int error, String errorMsg) {
            isSyncingContactInfosWithServer = false;
            if (callback != null) {
                callback.onError(error, errorMsg);
            }
        }

    });

}
 
开发者ID:nggirl,项目名称:EaseChatDemo,代码行数:32,代码来源:UserProfileManager.java

示例13: init

import com.easemob.chat.EMChat; //导入依赖的package包/类
/**
 * this function will initialize the HuanXin SDK
 *
 * @param context
 * @return
 */
public synchronized boolean init(Context context) {
    if (sdkInited) {
        return true;
    }
    appContext = context;

    int pid = android.os.Process.myPid();
    String processAppName = getAppName(pid);

    Log.d(TAG, "process app name : " + processAppName);

    // 如果app启用了远程的service,此application:onCreate会被调用2次
    // 为了防止环信SDK被初始化2次,加此判断会保证SDK被初始化1次
    // 默认的app会在以包名为默认的process name下运行,如果查到的process name不是app的process name就立即返回
    if (processAppName == null || !processAppName.equalsIgnoreCase(appContext.getPackageName())) {
        Log.e(TAG, "enter the service process!");

        // 则此application::onCreate 是被service 调用的,直接返回
        return false;
    }
    // 初始化环信SDK,一定要先调用init()
    EMChat.getInstance().init(context);

    initChatOptions();
    if (settingsProvider == null) {
        settingsProvider = new DefaultSettingsProvider();
    }

    sdkInited = true;
    return true;
}
 
开发者ID:nggirl,项目名称:EaseChatDemo,代码行数:38,代码来源:EaseUI.java

示例14: onCreate

import com.easemob.chat.EMChat; //导入依赖的package包/类
@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		//设置推送昵称
		DemoApplication.currentUserNick = DemoApplication.getInstance().getUsernNickName();
		initView();
		inviteMessgeDao = new InviteMessgeDao(this);
		userDao = new UserDao(this);

		zainaFrament = new ZainaFragment();
		gushiFrament = new Zaina_gushi_Fragment();
		//这个fragment只显示好友和群组的聊天记录
//		chatHistoryFragment = new ChatHistoryFragment();
		//显示所有人消息记录的fragment
		chatHistoryFragment = new ChatAllHistoryFragment();
		contactListFragment = new ContactlistFragment();
		settingFragment = new SettingsFragment();
		//fragments = new Fragment[] { chatHistoryFragment, contactListFragment, settingFragment };
		fragments = new Fragment[] { zainaFrament , gushiFrament , chatHistoryFragment, contactListFragment, settingFragment };

		// 添加显示第一个fragment
	/*	getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, chatHistoryFragment)
				.add(R.id.fragment_container, contactListFragment).hide(contactListFragment).show(chatHistoryFragment)
				.commit();*/
		getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, zainaFrament)
				.add(R.id.fragment_container, contactListFragment).hide(contactListFragment).show(chatHistoryFragment)
				.commit();

		// 注册一个接收消息的BroadcastReceiver
		msgReceiver = new NewMessageBroadcastReceiver();
		IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction());
		intentFilter.setPriority(3);
		registerReceiver(msgReceiver, intentFilter);

		// 注册一个ack回执消息的BroadcastReceiver
		IntentFilter ackMessageIntentFilter = new IntentFilter(EMChatManager.getInstance()
				.getAckMessageBroadcastAction());
		ackMessageIntentFilter.setPriority(3);
		registerReceiver(ackMessageReceiver, ackMessageIntentFilter);

		// 注册一个离线消息的BroadcastReceiver
		IntentFilter offlineMessageIntentFilter = new IntentFilter(EMChatManager.getInstance()
				.getOfflineMessageBroadcastAction());
		registerReceiver(offlineMessageReceiver, offlineMessageIntentFilter);

		// setContactListener监听联系人的变化等
		EMContactManager.getInstance().setContactListener(new MyContactListener());
		// 注册一个监听连接状态的listener
		EMChatManager.getInstance().addConnectionListener(new MyConnectionListener());
		// 注册群聊相关的listener
		EMGroupManager.getInstance().addGroupChangeListener(new MyGroupChangeListener());
		// 通知sdk,UI 已经初始化完毕,注册了相应的receiver和listener, 可以接受broadcast了
		EMChat.getInstance().setAppInited();
		/****新增****/
		loadcontact();
		//showFloatingButton();暂时注释
	}
 
开发者ID:macyuan,项目名称:TAG,代码行数:59,代码来源:MainActivity_0903.java

示例15: uploadlog

import com.easemob.chat.EMChat; //导入依赖的package包/类
public void uploadlog() {

		if (progressDialog == null)
			progressDialog = new ProgressDialog(this);
		progressDialog.setMessage("上传日志中...");
		progressDialog.setCancelable(false);
		progressDialog.show();

		EMChat.getInstance().uploadLog(new EMCallBack() {

			@Override
			public void onSuccess() {
				runOnUiThread(new Runnable() {

					@Override
					public void run() {
						progressDialog.dismiss();
						Toast.makeText(DiagnoseActivity.this, "日志上传成功",
								Toast.LENGTH_SHORT).show();
					}
				});
			}

			@Override
			public void onProgress(final int progress, String status) {
				// getActivity().runOnUiThread(new Runnable() {
				//
				// @Override
				// public void run() {
				// progressDialog.setMessage("上传中 "+progress+"%");
				//
				// }
				// });

			}

			@Override
			public void onError(int code, String message) {
				EMLog.e("###", message);
				runOnUiThread(new Runnable() {

					@Override
					public void run() {
						progressDialog.dismiss();
						Toast.makeText(DiagnoseActivity.this, "log上传失败",
								Toast.LENGTH_SHORT).show();
					}
				});

			}
		});

	}
 
开发者ID:macyuan,项目名称:TAG,代码行数:54,代码来源:DiagnoseActivity.java


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