openfire+asmack搭建的安卓即时通讯(四) 15.4.10
来源:互联网 发布:mobi格式软件ios 编辑:程序博客网 时间:2024/06/02 19:42
之前的教程不知道你们成功了没,,,没成功可以问我啊=-=
第四篇博文是要实现发送消息的功能。
首先在我们登陆后的活动的layout里添加这样的两个控件,一个EditText和一个Button用于发送数据
1 <EditText android:id="@+id/edit_text_out" 2 android:layout_width="0dp" 3 android:layout_height="wrap_content" 4 android:layout_weight="1" 5 android:layout_gravity="bottom" 6 android:hint="说点什么呢?" 7 /> 8 <Button 9 android:id="@+id/button_send"10 android:layout_width="wrap_content"11 android:layout_height="wrap_content"12 android:scaleType="centerCrop"13 android:text="sent"14 android:layout_gravity="bottom"15 android:background="#00000000"16 />
然后回到该活动,添加Button和Button的监听事件:
1 Button button=(Button)findViewById(R.id.button_send); //找到Button 2 button.setOnClickListener(new View.OnClickListener() { 3 @Override 4 public void onClick(View v) { 5 EditText input=(EditText) findViewById(R.id.edit_text_out); //找到EditText 6 final String content=input.getText().toString(); //把里面的东西去出来转化为字符串 7 Log.i(username+"说===", content); //打印在日志里 8 try { 9 XMPPConnection connection = connect.getConnection(); //与服务器进行连接10 ChatManager cm = connection.getChatManager(); 11 Chat chat=cm.createChat(“admin@172.6.33.68/Spark 2.6.3”, new MessageListener() {//传入两个参数一个是说话对象:这里我们放入我们服务器管理员的名字写的时候要加ip和版本号,第二个参数是消息的监听者12 @Override13 public void processMessage(Chat chat, Message msg) { //设置消息的监听14 msg.setBody(content); //msg(注意是asmack包里的)把我们取出的输入内容放进去15 Log.i(msg.getFrom() + "说:" + msg.getBody()); //打印日志16 17 }18 });19 Message m = new Message(); //把信息发送给对方20 m.setBody(content); 21 chat.sendMessage(m.getBody());22 } catch (XMPPException e) {23 e.printStackTrace();24 }25 }26 });
在编辑栏输入一堆东西
我们就能看到服务器端的打印数据了,一次是发送监听到的,一次是接收监听到的
我们在打开Spark的客户端给我们的虚拟机登录用户发送一条数据:
我们在Spark的客户端登录admin就能接收到这条消息了!
这样我们就既能发送数据,又能接收数据了!客户端的初级功能就基本完成
明天或者下午有空的话会写下一篇,进行简单的美化和修整,毕竟总不能界面这么丑,接受发送还靠打印日志啊!
求推荐=-=!
0 0
- openfire+asmack搭建的安卓即时通讯(四) 15.4.10
- openfire+asmack搭建的安卓即时通讯(一) 15.4.7
- openfire+asmack搭建的安卓即时通讯(二) 15.4.9
- openfire+asmack搭建的安卓即时通讯(三) 15.4.9
- openfire+asmack搭建的安卓即时通讯(五) 15.4.12
- 基于openfire+asmack+spark修改的即时通讯
- android即时通讯软件开发教程(asmack+openfire+spark)一
- 即时通讯实现方式(采用openfire和asmack方式)
- XMPP(二)-基于asmack+openfire的安卓客户端(仿QQ)的介绍以及个人心得
- XMPP(二)-基于asmack+openfire的安卓客户端(仿QQ)的介绍以及个人心得
- 搭建基于Openfire的即时通讯系统
- Openfire + Smack 即时通讯(一)环境搭建
- jwchat+openfire搭建即时通讯
- 基于Xmpp openfire asmack 即时通讯开发 传输文件注意事项
- Android XMPP聊天的实现(asmack+openfire)
- openfire + asmack
- XMPP与Openfire搭建的iOS即时通讯问题
- Mac下即时通讯openfire在本地搭建(Eclipse)
- (转)你只是看起来很努力
- invalidate和postInvalidate的区别
- openfire+asmack搭建的安卓即时通讯(一) 15.4.7
- openfire+asmack搭建的安卓即时通讯(二) 15.4.9
- openfire+asmack搭建的安卓即时通讯(三) 15.4.9
- openfire+asmack搭建的安卓即时通讯(四) 15.4.10
- openfire+asmack搭建的安卓即时通讯(五) 15.4.12
- innobackupex<五、参数详解>
- Opencv 图片的初步处理——平滑处理
- windows服务
- mybatis中的#和$的区别以及mybatis like查询
- String与StringBufer区别
- 解决 cmd dos 下 无法显示中文
- timeval