硅谷社交1--环信集成

来源:转载

1.环信SDK介绍

(1)登录环信官方网站
           http://www.easemob.com/

(2)注册账号

(3)阅读集成文档
      ①环信平台架构
      ②环信后台数据处理
      ③环信中数据的传递

(4)下载SDK


2)环信的Demo演示
(1)检查demo的gradle版本和android studio的gradle版本是否一致
1.项目的build.gradle

buildscript {

repositories {

jcenter()

}

dependencies {

// classpath 'com.android.tools.build:gradle:2.1.2'

classpath 'com.android.tools.build:gradle:1.5.0'

}

}

2.项目的gradle文件夹

#Fri May 20 14:56:58 CST 2016

distributionBase=GRADLE_USER_HOME

distributionPath=wrapper/dists

zipStoreBase=GRADLE_USER_HOME

zipStorePath=wrapper/dists

#distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip

(2)如果修改后,还是编译不通过,可以在build.gradle中修改

dependencies {

compile project(':redpacketlibrary')

compile project(':EaseUI')

compile fileTree(dir: 'libs', include: '*.jar', exclude: 'android-support-multidex.jar')

//考虑到在eclipse中,直接使用源码

// compile ('com.anthonycr.grant:permissions:1.0'){

// exclude module: 'support-v4'

// }

// 从v7包中移除v4

compile ('com.android.support:appcompat-v7:23.4.0'){

exclude module: 'support-v4'

}

}

3.集成EaseUI
(1)将EaseUI模块导入到项目中,并关联到主项目中
(2)配置AndroidManifest.xml清单文件

// 配置权限

<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.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" />

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

<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />

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

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

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

<!-- 设置环信应用的appkey -->

<meta-data

android:name="EASEMOB_APPKEY"

android:value="atguigudemo#demo" />

<!-- 声明sdk所需的service -->

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

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>

(3)在环信官网上创建应用
(4)创建IMApplication,初始化EaseUI

public class IMApplication extends Application {

private static Context mContext;

@Override

public void onCreate() {

super.onCreate();

EMOptions options = new EMOptions();

options.setAutoAcceptGroupInvitation(false);// 不自动接受群邀请信息

options.setAcceptInvitationAlways(false);// 不总是一直接受所有邀请

// 初始化EaseUI

EaseUI.getInstance().init(this,options);

// 初始化模型层数据

Modle.getInstance().init(this);

mContext = this;

}

// 获取全局上下文

public static Context getApplication(){

return mContext;

}

}

// 在AndroidManifest.xml中关联

<application

android:name=".IMApplication"

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:supportsRtl="true"

android:theme="@style/AppTheme">

</application>

(5)错误解决

编译后报如下错误

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\Program Files\Java\jdk1.7.0_45\bin\java.exe'' finished with non-zero exit value 2

错误原因:EaseUI中的v4包和主项目中的v7包冲突,

解决办法:在项目的build.gradle将v7包中的v4包移除

dependencies {

compile fileTree(dir: 'libs', include: ['*.jar'])

testCompile 'junit:junit:4.12'

compile ('com.android.support:appcompat-v7:23.4.0'){

exclude module: 'support-v4'

}

compile project(':easeui')

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: