基于xmpp openfire smack 开发(四)单聊
来源:互联网 发布:全国最大数据库 编辑:程序博客网 时间:2024/05/01 04:34
1、
class Thread1 extends Thread {@Overridepublic void run() {uid = preferences.getString("uid", "0");if (!uid.equals("0")) {Login(Content.DaTingSERVICE_URL, 5222, uid, "111111", uid + "@"+ Content.DaTingSERVICE_Name);} else {handler.sendEmptyMessage(4);Intent intent = new Intent(SiXinActivity.this,LoginActivity.class);SiXinActivity.this.startActivity(intent);exitApp();}}}2、
public void Login(final String ServerIP, final int serverport,final String Username, final String Password, String userid) {UserId = userid;preferences = GoosunApplication.mApplication.getPreferences();User = WonickName + "#" + uid + "#" + WoUrl;connConfig = new ConnectionConfiguration(ServerIP, serverport,Content.DaTingSERVICE_Name);connConfig.setReconnectionAllowed(true);connConfig.setSASLAuthenticationEnabled(false);connConfig.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);xmppConnection = new XMPPConnection(connConfig);new Thread() {@Overridepublic void run() {try {xmppConnection.connect();xmppConnection.login(Username, Password);RegisterMessageListener();} catch (Exception ex) {ex.printStackTrace();handler.sendEmptyMessage(3);}}}.start();}3、
// 注册单人对话监听protected void RegisterMessageListener() {chatManager = xmppConnection.getChatManager();chatManager.addChatListener(new ChatManagerListener() {public void chatCreated(Chat chat, boolean arg1) {chat.addMessageListener(new MessageListener() {public void processMessage(Chat arg0, Message message) {String msg = message.getBody();String fromString = message.getFrom();if (msg.contains("危险")) {}sendhandlemsg(msg,fromString,0);}});}});}
4、
// 发送1 to 1的消息public void semdmessage(final String msg, final String msgto) {// 初始化发送消息chat = chatManager.createChat(msgto, null);new Thread() {@Overridepublic void run() {try {chat.sendMessage(msg);sendhandlemsg(msg,User,1);} catch (XMPPException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}.start();}5、
public void sendhandlemsg(String msg,String fromString,int i){entity = new ChatMsgEntity();fromString=TanickName+"#"+TaUid+"#"+TaUrl;if(i==0){entity.setMsgType(true);entity.setName(fromString);}else{entity.setMsgType(false);entity.setName(User);}entity.setDate(new Date());entity.setText(msg.toString());mDataArrays.add(entity);handler.sendEmptyMessage(1);}6、
private void send() {contString = mEditTextContent.getText().toString();if ("".equals(contString.trim())) {Toast.makeText(this, "不能发送空白消息", Toast.LENGTH_SHORT).show();} else if (contString.length() > 0) {semdmessage(contString, TaUid + "@" + Content.DaTingSERVICE_Name);msgStr = null;mEditTextContent.setText(null);}}
7、
public Handler handler = new Handler(Looper.myLooper()) {public void handleMessage(android.os.Message msg) {super.handleMessage(msg);switch (msg.what) {case 1:mAdapter.notifyDataSetChanged();mListView.setSelection(mListView.getCount() - 1);zhuangtai = true;break;
0 0
- 基于xmpp openfire smack 开发(四)单聊
- Android基于XMPP Smack openfire 开发的聊天室(四) 【创建房间、表单;报文】
- Android基于XMPP Smack openfire 开发的聊天室(四) 【创建房间、表单;报文】
- Android基于XMPP Smack openfire 开发的聊天室(四) 【创建房间、表单;报文】
- Android基于XMPP Smack openfire 开发的聊天室(四) 【创建房间、表单;报文】
- Android基于XMPP Smack openfire 开发的聊天室(四) 【创建房间、表单;报文】
- Android基于XMPP Smack openfire 开发的聊天室(一)
- 基于xmpp openfire smack 开发(一)群聊
- Android基于XMPP Smack openfire 开发的聊天室(一)
- 基于xmpp openfire smack 开发(三)群聊发送图片
- 基于xmpp openfire smack开发之openfire介绍和部署
- Android基于XMPP Smack Openfire开发IM【四】初步实现两个客户端通信
- Android基于XMPP Smack Openfire开发IM(1)搭建openfire服务器
- Android基于XMPP Smack Openfire开发IM(2)登录openfire
- Android基于XMPP Smack Openfire开发IM(2)登录openfire
- 基于xmpp openfire smack开发之Android客户端开发[3]
- 基于xmpp openfire smack开发之Android客户端开发[3]
- 基于xmpp openfire smack开发之Android客户端开发[3]
- Android的onCreateOptionsMenu()创建菜单Menu详解
- 正则表达式的使用
- 一套配色完整的Metro风格PSD源文件
- 使用jython和ScriptEngineManager在java中执行python
- 利用QR算法求解矩阵的特征值和特征向量
- 基于xmpp openfire smack 开发(四)单聊
- 01-复杂度2.Maximum Subsequence Sum
- 1012. The Best Rank (25)暴力枚举 排序
- 【HBase基础教程】1、HBase之单机模式与伪分布式模式安装
- nfs:server is not responding,still trying 原因与解决方案
- 数据结构--二叉序树
- emacs配置文件路径
- 大数据博客
- Majority Element