本文整理汇总了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());
// }
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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;
}
示例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);
}
}
});
}
示例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;
}
示例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();
}
示例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();
}
示例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);
}
}
});
}
示例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;
}
示例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);
}
}
});
}
示例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;
}
示例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();暂时注释
}
示例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();
}
});
}
});
}