简单的asmack应用
package com.virtual.robot.main;
创新互联专注于企业营销型网站、网站重做改版、固镇网站定制设计、自适应品牌网站建设、H5开发、商城网站开发、集团公司官网建设、成都外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为固镇等各大城市提供网站开发制作服务。
import java.util.Timer;
import java.util.TimerTask;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManager;
import org.jivesoftware.smack.XMPPConnection;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Window;
import android.view.WindowManager;
import com.virtual.robot.R;
import com.virtual.robot.common.ExitApplication;
/**
* start project
* @author zhuolin
*
*/
public class StartActivity extends ActionBarActivity {
public static XMPPConnection con;
public static Chat newChat;
public static ChatManager chatmanager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.startproject);
ExitApplication.getInstance().addActivity(this);
TimerTask task = new TimerTask() {
@Override
public void run() {
Intent intent = new Intent(StartActivity.this, ChooseLoginActivity.class);
startActivity(intent);
// TipMessage.logDebug("11111111111111111111111111111111");
// try {
// // Create a connection to server
// ConnectionConfiguration config = new ConnectionConfiguration(
// "192.168.1.107", 5222);
// config.setSASLAuthenticationEnabled(false);
// config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
// con = new XMPPConnection(config);
//
// // connect and login with the username and pwd on server
// con.connect();
// con.login("zhuolin", "111111");
// TipMessage.logDebug("2222222222Authenticated = " + con.isAuthenticated());
//
// // add a listener to receive all messages
// addListener();
//
// chatmanager = con.getChatManager();
// newChat = chatmanager.createChat("zhuolin2@tclim/Spark 2.6.3",
// new MessageListener() {
// public void processMessage(Chat chat, Message message) {
// TipMessage.logDebug("I'm sending: "
// + message.getBody());
// }
// });
// newChat.sendMessage("hi");
// } catch (XMPPException e) {
// e.printStackTrace();
// } finally {
// //让线程休眠 然后再关闭连接
// try {
// Thread.sleep(30000);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// con.disconnect();
// }
}
};
Timer timer = new Timer();
timer.schedule(task, 1200);
}
//public static void addListener() {
// // just need Messages
// PacketFilter filterMessage = new PacketTypeFilter(Message.class);
//
// PacketListener myListener = new PacketListener() {
// public void processPacket(Packet packet) {
// TipMessage.logDebug("From: " + packet.getFrom() + "\n");
// System.out.println("Body: " + ((Message) packet).getBody());
// // when receiving prc's Message, just say something else again
// // and again, robot
// try {
// newChat.sendMessage("hi again");
// } catch (XMPPException e) {
// e.printStackTrace();
// }
// }
// };
// // register the listener to the connection
// con.addPacketListener(myListener, filterMessage);
// }
}
文章名称:简单的asmack应用
网页路径:http://pwwzsj.com/article/pogchs.html