聊天(环信)
2016-05-30 09:37
260 查看
在聊天的界面应该创建一个activity,然后再写一个application(别忘了继承),然后导入IMsdk(环信)
这是在activity中继承fragmentactivity;
package com.example.markingfriends;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.hyphenate.easeui.EaseConstant;
import com.hyphenate.easeui.ui.EaseChatFragment;
public class CallActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.call_activity);
//new出EaseChatFragment或其子类的实例
EaseChatFragment chatFragment = new EaseChatFragment();
//传入参数
Bundle args = new Bundle();
args.putInt(EaseConstant.EXTRA_CHAT_TYPE, EaseConstant.CHATTYPE_GROUP);
args.putString(EaseConstant.EXTRA_USER_ID, "zw123");
chatFragment.setArguments(args);
getSupportFragmentManager().beginTransaction().add(R.id.fl_call_fl, chatFragment).commit();
}
}
在创建一个application;
package com.example.adapter;
import android.app.Application;
import com.hyphenate.chat.EMOptions;
import com.hyphenate.easeui.controller.EaseUI;
public class App extends Application{
@Override
public void onCreate() {
super.onCreate();
EMOptions options = new EMOptions();
// 默认添加好友时,是不需要验证的,改成需要验证
options.setAcceptInvitationAlways(false);
EaseUI.getInstance().init(getApplicationContext(), options);
}
}
XML布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/fl_call_fl"
android:layout_width="match_parent"
android:layout_height="match_parent"
></FrameLayout>
</LinearLayout>
这是在activity中继承fragmentactivity;
package com.example.markingfriends;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.hyphenate.easeui.EaseConstant;
import com.hyphenate.easeui.ui.EaseChatFragment;
public class CallActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.call_activity);
//new出EaseChatFragment或其子类的实例
EaseChatFragment chatFragment = new EaseChatFragment();
//传入参数
Bundle args = new Bundle();
args.putInt(EaseConstant.EXTRA_CHAT_TYPE, EaseConstant.CHATTYPE_GROUP);
args.putString(EaseConstant.EXTRA_USER_ID, "zw123");
chatFragment.setArguments(args);
getSupportFragmentManager().beginTransaction().add(R.id.fl_call_fl, chatFragment).commit();
}
}
在创建一个application;
package com.example.adapter;
import android.app.Application;
import com.hyphenate.chat.EMOptions;
import com.hyphenate.easeui.controller.EaseUI;
public class App extends Application{
@Override
public void onCreate() {
super.onCreate();
EMOptions options = new EMOptions();
// 默认添加好友时,是不需要验证的,改成需要验证
options.setAcceptInvitationAlways(false);
EaseUI.getInstance().init(getApplicationContext(), options);
}
}
XML布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/fl_call_fl"
android:layout_width="match_parent"
android:layout_height="match_parent"
></FrameLayout>
</LinearLayout>
相关文章推荐
- JS组件Bootstrap Table使用实例分享
- 更新应用手机上会出现两个图标,删也删不掉。
- PS制作逼真的下雨效果
- [置顶] 【Android】Android开发点击查看手机电量的小功能。学习广播的一个小技能小Demo
- 寻找最高分成绩的学生
- sdau三 1006
- pod1.0后安装第三方库后无法通过编译
- java 利用SMB读取远程文件
- 汉字的unicode范围
- 如果你很忙,你一定在什么地方做错了!
- Java中Set集合的使用
- js 将 json 字符串转换为 json 对象
- Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
- 计算机程序的思维逻辑 (17) - 继承实现的基本原理
- iOS获得UITextView当前光标所在的位置.
- Mybatis map value 等于null无法获取值
- secureCRT软件如何用密钥登录linux系统
- 魅族手机无法连接ubuntu系统的问题
- ajax跨域问题
- 传值