首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

Android XMPP例子(Openfire+asmack+spark)

移动开发 2MB 20 需要积分: 1
立即下载

资源介绍:

Android XMPP例子(Openfire+asmack+spark)
package com.xmpp.client; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Timer; import java.util.TimerTask; import org.jivesoftware.smack.Chat; import org.jivesoftware.smack.ChatManager; import org.jivesoftware.smack.ChatManagerListener; import org.jivesoftware.smack.MessageListener; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smackx.filetransfer.FileTransfer; import org.jivesoftware.smackx.filetransfer.FileTransfer.Status; import org.jivesoftware.smackx.filetransfer.FileTransferListener; import org.jivesoftware.smackx.filetransfer.FileTransferManager; import org.jivesoftware.smackx.filetransfer.FileTransferRequest; import org.jivesoftware.smackx.filetransfer.IncomingFileTransfer; import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer; import com.xmpp.client.util.TimeRender; import com.xmpp.client.util.XmppTool; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; public class FormClient extends Activity { private MyAdapter adapter; private List listMsg = new ArrayList(); private String pUSERID; private EditText msgText; private ProgressBar pb; public class Msg { String userid; String msg; String date; String from; public Msg(String userid, String msg, String date, String from) { this.userid = userid; this.msg = msg; this.date = date; this.from = from; } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.formclient); this.pUSERID = getIntent().getStringExtra("USERID"); ListView listview = (ListView) findViewById(R.id.formclient_listview); listview.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL); this.adapter = new MyAdapter(this); listview.setAdapter(adapter); this.msgText = (EditText) findViewById(R.id.formclient_text); this.pb = (ProgressBar) findViewById(R.id.formclient_pb); //message listener ChatManager cm = XmppTool.getConnection().getChatManager(); final Chat newchat = cm.createChat("test2@sam", null); cm.addChatListener(new ChatManagerListener() { @Override public void chatCreated(Chat chat, boolean able) { chat.addMessageListener(new MessageListener() { @Override public void processMessage(Chat chat2, Message message) { //message from user [test2@sam] if(message.getFrom().contains("test2@sam")){ String[] args = new String[] { "test2", message.getBody(), TimeRender.getDate(), "IN" }; android.os.Message msg = handler.obtainMessage(); msg.what = 1; msg.obj = args; msg.sendToTarget(); }else{ // orther user / group / admin of the openfire // do work... } } }); } }); //send file Button btattach = (Button) findViewById(R.id.formclient_btattach); btattach.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(FormClient.this, FormFiles.class); startActivityForResult(intent, 2); } }); //send message Button btsend = (Button) findViewById(R.id.formclient_btsend); btsend.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String msg = msgText.getText().toString(); if(msg.length() > 0){ listMsg.add(new Msg(pUSERID, msg, TimeRender.getDate(), "OUT")); adapter.notifyDataSetChanged(); try { newchat.sendMessage(msg); } catch (XMPPException e) { e.printStackTrace(); } } msgText.setText(""); } }); //receive file FileTransferManager fileTransferManager = new FileTransferManager(XmppTool.getConnection()); fileTransferManager.addFileTransferListener(new RecFileTransferListener()); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode==2 && resultCode==2 && data!=null){ String filepath = data.getStringExtra("filepath"); if(filepath.length() > 0){ sendFile(filepath); } } } private void sendFile(String filepath) { // ServiceDiscoveryManager sdm = new ServiceDiscoveryManager(connection); final FileTransferManager fileTransferManager = new FileTransferManager(XmppTool.getConnection()); final OutgoingFileTransfer fileTransfer = fileTransferManager.createOutgoingFileTransfer("test2@sam/Spark 2.6.3"); final File file = new File(filepath); try { fileTransfer.sendFile(file, "Sending"); } catch (Exception e) { e.printStackTrace(); } new Thread(new Runnable() { @Override public void run() { try{ while (true) { Thread.sleep(500L); Status status = fileTransfer.getStatus(); if ((status == FileTransfer.Status.error) || (status == FileTransfer.Status.complete) || (status == FileTransfer.Status.cancelled) || (status == FileTransfer.Status.refused)) { handler.sendEmptyMessage(4); break; }else if(status == FileTransfer.Status.negotiating_transfer){ //.. }else if(status == FileTransfer.Status.negotiated){ //.. }else if(status == FileTransfer.Status.initial){ //.. }else if(status == FileTransfer.Status.negotiating_stream){ //.. }else if(status == FileTransfer.Status.in_progress){ handler.sendEmptyMessage(2); long p = fileTransfer.getBytesSent() * 100L / fileTransfer.getFileSize(); android.os.Message message = handler.obtainMessage(); message.arg1 = Math.round((float) p); message.what = 3; message.sendToTarget(); } } } catch (Exception e) { e.printStackTrace(); } } }).start(); } private FileTransferRequest request; private File file; class RecFileTransferListener implements FileTransferListener { @Override public void fileTransferRequest(FileTransferRequest prequest) { System.out.println("The file received from: " + prequest.getRequestor()); file = new File("mnt/sdcard/" + prequest.getFileName()); request = prequest; handler.sendEmptyMessage(5); } } private Handler handler = new Handler() { public void handleMessage(android.os.Message msg) { switch (msg.what) { case 1: String[] args = (String[]) msg.obj; listMsg.add(new Msg(args[0], args[1], args[2], args[3])); adapter.notifyDataSetChanged(); break; case 2: if(pb.getVisibility()==View.GONE){ pb.setMax(100); pb.setProgress(0); pb.setVisibility(View.VISIBLE); } break; case 3: pb.setProgress(msg.arg1); break; case 4: pb.setVisibility(View.GONE); break; case 5: final IncomingFileTransfer infiletransfer = request.accept(); AlertDialog.Builder builder = new AlertDialog.Builder(FormClient.this); builder.setTitle("receive file") .setCancelable(false) .setPositiveButton("Receive", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { try { infiletransfer.recieveFile(file); } catch (XMPPException e) { e.printStackTrace(); } handler.sendEmptyMessage(2); Timer timer = new Timer(); TimerTask updateProgessBar = new TimerTask() { public void run() { if ((infiletransfer.getAmountWritten() >= request.getFi

资源文件列表:

AdXmpp.zip 大约有103个文件
  1. AdXmpp/
  2. AdXmpp/.classpath 417B
  3. AdXmpp/.project 842B
  4. AdXmpp/AndroidManifest.xml 1.34KB
  5. AdXmpp/assets/
  6. AdXmpp/bin/
  7. AdXmpp/bin/AdXmpp.apk 470.5KB
  8. AdXmpp/bin/classes/
  9. AdXmpp/bin/classes/com/
  10. AdXmpp/bin/classes/com/xmpp/
  11. AdXmpp/bin/classes/com/xmpp/client/
  12. AdXmpp/bin/classes/com/xmpp/client/FileAdapter$ViewHolder.class 484B
  13. AdXmpp/bin/classes/com/xmpp/client/FileAdapter.class 3.39KB
  14. AdXmpp/bin/classes/com/xmpp/client/FormClient$1$1$1.class 2.29KB
  15. AdXmpp/bin/classes/com/xmpp/client/FormClient$1$1.class 2.14KB
  16. AdXmpp/bin/classes/com/xmpp/client/FormClient$1$2.class 1.17KB
  17. AdXmpp/bin/classes/com/xmpp/client/FormClient$1.class 3.18KB
  18. AdXmpp/bin/classes/com/xmpp/client/FormClient$2$1.class 1.67KB
  19. AdXmpp/bin/classes/com/xmpp/client/FormClient$2.class 1.07KB
  20. AdXmpp/bin/classes/com/xmpp/client/FormClient$3.class 1005B
  21. AdXmpp/bin/classes/com/xmpp/client/FormClient$4.class 2.16KB
  22. AdXmpp/bin/classes/com/xmpp/client/FormClient$5.class 2.19KB
  23. AdXmpp/bin/classes/com/xmpp/client/FormClient$Msg.class 737B
  24. AdXmpp/bin/classes/com/xmpp/client/FormClient$MyAdapter.class 2.22KB
  25. AdXmpp/bin/classes/com/xmpp/client/FormClient$RecFileTransferListener.class 1.64KB
  26. AdXmpp/bin/classes/com/xmpp/client/FormClient.class 6.14KB
  27. AdXmpp/bin/classes/com/xmpp/client/FormFiles$1.class 1.81KB
  28. AdXmpp/bin/classes/com/xmpp/client/FormFiles.class 2.86KB
  29. AdXmpp/bin/classes/com/xmpp/client/FormLogin$1.class 1.12KB
  30. AdXmpp/bin/classes/com/xmpp/client/FormLogin$2.class 2.37KB
  31. AdXmpp/bin/classes/com/xmpp/client/FormLogin.class 2.29KB
  32. AdXmpp/bin/classes/com/xmpp/client/R$attr.class 331B
  33. AdXmpp/bin/classes/com/xmpp/client/R$drawable.class 602B
  34. AdXmpp/bin/classes/com/xmpp/client/R$id.class 1.25KB
  35. AdXmpp/bin/classes/com/xmpp/client/R$layout.class 577B
  36. AdXmpp/bin/classes/com/xmpp/client/R$string.class 389B
  37. AdXmpp/bin/classes/com/xmpp/client/R.class 510B
  38. AdXmpp/bin/classes/com/xmpp/client/util/
  39. AdXmpp/bin/classes/com/xmpp/client/util/TimeRender.class 767B
  40. AdXmpp/bin/classes/com/xmpp/client/util/TransferUtils.class 3.13KB
  41. AdXmpp/bin/classes/com/xmpp/client/util/XmppTool.class 1.24KB
  42. AdXmpp/bin/classes.dex 1012.7KB
  43. AdXmpp/bin/res/
  44. AdXmpp/bin/res/drawable/
  45. AdXmpp/bin/res/drawable/im.png 4.65KB
  46. AdXmpp/bin/res/drawable/incoming.9.png 1.86KB
  47. AdXmpp/bin/res/drawable/outgoing.9.png 1.89KB
  48. AdXmpp/bin/res/drawable-hdpi/
  49. AdXmpp/bin/res/drawable-hdpi/fileback.png 2.97KB
  50. AdXmpp/bin/res/drawable-hdpi/filetype.png 3.33KB
  51. AdXmpp/bin/res/drawable-hdpi/folder.png 4.05KB
  52. AdXmpp/bin/res/drawable-hdpi/icon.png 3.87KB
  53. AdXmpp/bin/res/drawable-hdpi/p12.png 10.71KB
  54. AdXmpp/bin/res/drawable-ldpi/
  55. AdXmpp/bin/res/drawable-ldpi/icon.png 1.5KB
  56. AdXmpp/bin/res/drawable-mdpi/
  57. AdXmpp/bin/res/drawable-mdpi/icon.png 2.15KB
  58. AdXmpp/bin/resources.ap_ 47.68KB
  59. AdXmpp/gen/
  60. AdXmpp/gen/com/
  61. AdXmpp/gen/com/xmpp/
  62. AdXmpp/gen/com/xmpp/client/
  63. AdXmpp/gen/com/xmpp/client/R.java 2.67KB
  64. AdXmpp/lib/
  65. AdXmpp/lib/asmack.jar 1.09MB
  66. AdXmpp/proguard.cfg 1.13KB
  67. AdXmpp/project.properties 360B
  68. AdXmpp/res/
  69. AdXmpp/res/drawable/
  70. AdXmpp/res/drawable/im.png 7.3KB
  71. AdXmpp/res/drawable/incoming.9.png 1.61KB
  72. AdXmpp/res/drawable/outgoing.9.png 1.64KB
  73. AdXmpp/res/drawable-hdpi/
  74. AdXmpp/res/drawable-hdpi/fileback.png 3.04KB
  75. AdXmpp/res/drawable-hdpi/filetype.png 3.4KB
  76. AdXmpp/res/drawable-hdpi/folder.png 6.71KB
  77. AdXmpp/res/drawable-hdpi/icon.png 4.05KB
  78. AdXmpp/res/drawable-hdpi/p12.png 10.76KB
  79. AdXmpp/res/drawable-ldpi/
  80. AdXmpp/res/drawable-ldpi/icon.png 1.68KB
  81. AdXmpp/res/drawable-mdpi/
  82. AdXmpp/res/drawable-mdpi/icon.png 2.51KB
  83. AdXmpp/res/layout/
  84. AdXmpp/res/layout/formclient.xml 1.91KB
  85. AdXmpp/res/layout/formclient_chat_in.xml 1.48KB
  86. AdXmpp/res/layout/formclient_chat_out.xml 1.56KB
  87. AdXmpp/res/layout/formlogin.xml 3.32KB
  88. AdXmpp/res/layout/frmfiles.xml 368B
  89. AdXmpp/res/layout/frmfiles_row.xml 543B
  90. AdXmpp/res/values/
  91. AdXmpp/res/values/strings.xml 104B
  92. AdXmpp/src/
  93. AdXmpp/src/com/
  94. AdXmpp/src/com/xmpp/
  95. AdXmpp/src/com/xmpp/client/
  96. AdXmpp/src/com/xmpp/client/FileAdapter.java 2.68KB
  97. AdXmpp/src/com/xmpp/client/FormClient.java 10.26KB
  98. AdXmpp/src/com/xmpp/client/FormFiles.java 1.8KB
  99. AdXmpp/src/com/xmpp/client/FormLogin.java 2.6KB
  100. AdXmpp/src/com/xmpp/client/util/
  101. AdXmpp/src/com/xmpp/client/util/TimeRender.java 395B
  102. AdXmpp/src/com/xmpp/client/util/TransferUtils.java 2.28KB
  103. AdXmpp/src/com/xmpp/client/util/XmppTool.java 806B
0评论
提交 加载更多评论
其他资源 MFC类库详解
MFC类库详解
CHM
Android 使用videoview播放Rtsp视频 demo
Android 使用videoview播放Rtsp视频 demo http://blog.csdn.net/huanzhongying/article/details/53032909
AD Type C 封装库 6Pin 24Pin分享(带3D视图)
介绍链接:https://blog.csdn.net/XiaoYuHaoAiMin/article/details/104171690 某宝有卖的6Pin 24Pin TypeC 接口AD封装库,包括3D视图,6Pin我做过一个东西的,自己画的,24Pin的来自互联网,技术有限,可能不提供支持!
月老情侣交友盲盒4.0.1源码
Redis 数据库 安装、配置、访问资源
【Redis】Redis 数据库 安装、配置、访问 ( Redis 简介 | 下载 Redis 安装包 | 安装 Redis 数据库 | 命令行访问 Redis | 使用可视化工具访问 Redis ) https://hanshuliang.blog.csdn.net/article/details/128945441 博客资源快照 001_Linux安装包 002_Windows安装包 003_可视化工具_Redis Desktop Manager
32个uniapp项目源码 涵盖商城团购等
源码列表: IT之家小程序版客户端(使用 Mpvue 开发,兼容 Web)ithome-lite-master.zip mpvue 仿网易严选mpvue-shop-master.zip mpvue-音乐播放器mpvue-music-master.zip mpvue性能测试与体验miniweibo-master.zip mpvue改造的日历.zip mpvue框架仿滴滴出行didi-master.zip mpVue高仿美团小程序教程mpvue-meituan-master.zip uni APP自动更新并安装.vue uni-app nvue沉浸式状态栏(线性渐变色).vue uni-app 二维码生成器分享wxqrcode.zip uni-app 侧边导航分类,适合商品分类页面uni-app-left-navigation-master.zip uni-app 自定义底部导航栏uni-app-bottom-navigation-master.zip uni-app全局变量的几种实现方式.zip uni-app的markdown富文本编辑器插件uniapp-
网上购物系统ssh
网上购物系统ssh毕业设计
FasterRcnn.zip
FasterRcnn的代码复现