程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA綜合教程 >> 硅谷社交1--環信集成,硅谷社交1--環

硅谷社交1--環信集成,硅谷社交1--環

編輯:JAVA綜合教程

硅谷社交1--環信集成,硅谷社交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')
}

  

參考文章:http://blog.csdn.net/easemob_im/article/details/41280147

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved