美文网首页三方
环信的集成

环信的集成

作者: A大心 | 来源:发表于2019-12-31 14:17 被阅读0次

    我们采用依赖库的方式进行集成

    第一步:官网下载Demo+SDK

    http://www.easemob.com/?utm_source=baidu-pp

    第二步进行解压:

    打开easeui中的build,因为版本问题,如果想去除警告,请修改以下依赖属性:

    修改前:

    修改后:

    然后,其它模块就可以使用它了

    错误解决:

    EaseChatRowImage

    因为版本升高会报一个AsyncTaskCompat找不到:

    解决如下:

    删掉这块代码(并不是这一行,我只截了一行,整个内部类都删掉)

    把以下代码复制上

    new AsyncTask<Object, Void, Bitmap>() {

    @Override

    protected Bitmap doInBackground(Object... args) {

                    File file = new File(thumbernailPath);

                    if (file.exists()) {

                            return EaseImageUtils.decodeScaleImage(thumbernailPath, 160, 160);

                    } else if (new File(imgBody.thumbnailLocalPath()).exists()) {

                            return EaseImageUtils.decodeScaleImage(imgBody.thumbnailLocalPath(), 160, 160);

                    }else {

                            if (message.direct() == EMMessage.Direct.SEND) {

                                        if (localFullSizePath != null && new File(localFullSizePath).exists()) {

                                                    return EaseImageUtils.decodeScaleImage(localFullSizePath, 160, 160);

                            } else {            

                                           return null;    

                            }

                            } else {

                                            return null;    

                            }

                        }    

                    }

    protected void onPostExecute(Bitmap image) {

                    if (image != null) {

                            imageView.setImageBitmap(image);

                            EaseImageCache.getInstance().put(thumbernailPath, image);

                    } else {

                                if (message.status() == EMMessage.Status.FAIL) { 

                                        if (isNetWorkConnected(activity)) { 

                                                    new Thread(new Runnable() {  

    @Override

    public void run() { 

                    EMClient.getInstance().chatManager().downloadThumbnail(message);

    }

        }).start();

            }    

        }

            }

    }

    }.execute();

    解决EaseImageView类中错误:

    修改为以下:

    初始化:

    EMOptions options = new EMOptions();

    // 默认添加好友时,是不需要验证的,改成需要验证

    options.setAcceptInvitationAlways(false);

    // 是否自动将消息附件上传到环信服务器,默认为True是使用环信服务器上传下载,如果设为 false,需要开发者自己处理附件消息的上传和下载

    options.setAutoTransferMessageAttachments(true);

    // 是否自动下载附件类消息的缩略图等,默认为 true 这里和上边这个参数相关联

    options.setAutoDownloadThumbnail(true);

    ...

    //初始化

    EMClient.getInstance().init(applicationContext, options);

    //在做打包混淆时,关闭debug模式,避免消耗不必要的资源

    EMClient.getInstance().setDebugMode(true);

    登录

    EMClient.getInstance().login(userName,password,new EMCallBack() {//回调

        @Override

        public void onSuccess() {

                EMClient.getInstance().groupManager().loadAllGroups();

                EMClient.getInstance().chatManager().loadAllConversations();

                Log.d("main", "登录聊天服务器成功!");

    }

    @Override

    public void onProgress(int progress, String status) {

    }

    @Override

    public void onError(int code, String message) {

                Log.d("main", "登录聊天服务器失败!");

    }

    });

    一定记得权限:

    <!-- Required -->

    <uses-permission android:name="android.permission.VIBRATE" />

    <uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="android.permission.RECORD_AUDIO" />

    <uses-permission android:name="android.permission.CAMERA" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-permission android:name="android.permission.GET_TASKS" />

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    切记更改APPKEY:

    设置环信应用的AppKey :

    <meta-data android:name="EASEMOB_APPKEY" android:value="Your AppKey" />

    声明SDK所需的service SDK核心功能:

    <service android:name="com.hyphenate.chat.EMChatService" android:exported="true"/>

            <service android:name="com.hyphenate.chat.EMJobService"

                    android:permission="android.permission.BIND_JOB_SERVICE"

                    android:exported="true"

             />

    声明SDK所需的receiver:

    <receiver android:name="com.hyphenate.chat.EMMonitorReceiver">

            <intent-filter>

                    <action android:name="android.intent.action.PACKAGE_REMOVED"/>

                    <data android:scheme="package"/>

            </intent-filter>

    <!-- 可选filter -->

            <intent-filter>

                    <action android:name="android.intent.action.BOOT_COMPLETED"/>

                    <action android:name="android.intent.action.USER_PRESENT" /> 

            </intent-filter>

    </receiver>

    相关文章

      网友评论

        本文标题:环信的集成

        本文链接:https://www.haomeiwen.com/subject/jgeboctx.html