聊天(环信)

在聊天的界面应该创建一个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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值