`
hylxinlang
  • 浏览: 129119 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

opnefire+android登录

阅读更多
package com.hyl.openfire;

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {
	private int PORT=5222;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		login("hyl1234","hyl1234");
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	public void login(String name,String pass){
		ConnectionConfiguration config = new ConnectionConfiguration("192.168.0.104", PORT);
		config.setSASLAuthenticationEnabled(false);
		XMPPConnection connection = new XMPPConnection(config);
		try {
			connection.connect();
			connection.login(name, pass);
			System.out.println("登录成功");
		} catch (XMPPException e) {
			System.out.println("登录失败");
			e.printStackTrace();
		}
		
	}

}

 

0
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics