之前做够在线及时聊天,小型企业基本上都是通过xmpp协议实现,但是我之前公司做的多多少少会出现一些问题,今天在查找资料的时候,无意发现了一个很好的东西,某公司开发了一套即时聊天sdk,虽然也是由xmpp协议开发,但是稳定性和实现简答方面确实容易得多,通俗易懂。关于公司名字不说了,大家自己去搜吧,不然等会有打广告嫌疑!
涵盖了android和ios,下面给出简单的sdk介绍:
Android SDK 使用指南
首先将libs文件夹下的appkefu_sdk.jar加入到项目工程libs文件夹下(如果没有,则创建文件夹,仅针对eclipse开发环境). 其次,将res文件夹下所有文件拷贝到项目res文件夹下。在项目中使用appkefu_sdk.jar主要有两种方式,具体可参考示例程序AppKeFuDemoSimple和AppKeFuDemoAdvanced, 二者的主要区别在于前者每次会话的时候都会尝试与服务器建立新的会话,当关闭聊天窗口的时候关闭会话,断开与服务器的链接。后者则尝试在项目启动的时候 建立与服务器的一次性会话,在项目运行期间,所有的会话窗口公用此会话链接,直到项目结束运行或者网络故障
AppKeFuDemoSimple 调用此方法启动会话窗口
[html]
<span style="font-family:Microsoft YaHei; font-size:14px">/**
* @param kefuName 客服的用户名
*/
private void startChat(String kefuName) {
Log.d(TAG, "startChat:"+kefuName);
String jid = kefuName + "@appkefu.com";
Intent intent = new Intent(this, ChatActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Contact contact = new Contact(jid);
intent.setData(contact.toUri());
startActivity(intent);
}</span>
AppKeFuDemoSimple 在AndroidManifest.xml中添加:
[html]
<span style="font-family:Microsoft YaHei; font-size:14px"> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" /></span>
和
[html]
<span style="font-family:Microsoft YaHei; font-size:14px"> <activity android:name="com.appkefu.lib.ChatActivity" android:theme="@android:style/Theme.NoTitleBar" />
<service android:name="com.appkefu.lib.service.AppService" /></span>
AppKeFuDemoAdvanced 主要分为四部分:AppKeFuApplication,MainActivity,LoginActivity和AndroidManifest.xml
[html]
<span style="font-family:Microsoft YaHei; font-size:14px"> import android.app.Application;
/**
* @author Administrator
*
*/
public class AppKeFuApplication extends Application {
private boolean mIsConnected = false;
public AppKeFuApplication(){
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onTerminate() {
super.onTerminate();
}
public boolean isConnected() {
return mIsConnected;
}
public void setConnected(boolean isConnected) {
mIsConnected = isConnected;
}
}
</span>
[html]
<span style="font-family:Microsoft YaHei; font-size:14px">import com.appkefu.lib.ChatViewActivity;
import com.appkefu.lib.service.Contact;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
private static final String TAG = MainActivity.class.getSimpleName();
private static final int LOGIN_REQUEST_CODE = 1;
private Button chatAdmin;
private Button chatKeFu1;
private Button chatKeFu2;
private AppKeFuApplication app;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chatAdmin = (Button)findViewById(R.id.chat_admin);
chatAdmin.setOnClickListener(listener);
chatKeFu1 = (Button)findViewById(R.id.chat_kefu1);
chatKeFu1.setOnClickListener(listener);
chatKeFu2 = (Button)findViewById(R.id.chat_kefu2);
chatKeFu2.setOnClickListener(listener);
app = (AppKeFuApplication)getApplication();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart");
if(!app.isConnected()){
Log.d(TAG, "start login");
Intent login = new Intent(this, LoginActivity.class);
startActivityForResult(login, LOGIN_REQUEST_CODE);
}
else
{
Log.d(TAG, "already logged in");
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == LOGIN_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK)
{
Log.d(TAG, "Activity.RESULT_OK");
app.setConnected(true);
}
else if (resultCode == Activity.RESULT_CANCELED)
{
Log.d(TAG, "Activity.RESULT_CANCELED");
app.setConnected(false);
chatAdmin.setEnabled(false);
chatKeFu1.setEnabled(false);
chatKeFu2.setEnabled(false);
Toast.makeText(this, "登录失败", Toast.LENGTH_LONG).show();
}
}
}
@Override
protected void onRestart() {
super.onRestart(); <
补充:移动开发 , Android ,