Chat21은 오픈 소스 라이브 채팅 플랫폼 Tiledesk.com의 핵심입니다.
Chat21 Android SDK를 사용하면 다음과 같습니다.
| |
|
데모 앱 소스 코드는 여기에서 사용할 수 있습니다
Yo는 공식 튜토리얼에 따라 자신의 채팅을 만들 수 있습니다.
시작하기 전에 환경에서 설정할 몇 가지 사항이 필요합니다.
먼저 Google-Services 플러그인과 Google의 Maven 저장소를 루트 레벨 Build.gradle 파일에 포함시킵니다.
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.1.1'
}
}
allprojects {
// ...
repositories {
// ...
google()
}
}
그런 다음 모듈 Gradle 파일 (일반적으로 app/build.gradle)에서 파일 하단에 플러그인 라인을 추가하여 Gradle 플러그인을 활성화합니다.
apply plugin: 'com.android.application'
// ...
dependencies {
// ...
implementation "com.google.android.gms:play-services:11.8.0"
}
// ...
apply plugin: 'com.google.gms.google-services'
세트:
App/Build.gradle 파일에 다음을 추가하십시오.
defaultConfig {
// ...
multiDexEnabled true
}
dependencies {
// ...
compile 'com.android.support:multidex:1.0.1'
compile "com.google.android.gms:play-services:11.8.0"
compile 'com.android.support:design:26.1.0'
compile 'org.chat21.android:chat21:1.0.10'
compile 'com.vanniktech:emoji-ios:0.5.1'
}
// ...
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '26.1.0'
}
}
}
}
마지막으로 문서에 설명 된 대로이 문장을 파일의 마지막 줄로 붙여 넣습니다.
apply plugin: 'com.google.gms.google-services'
결국 google-services.json 파일을 다운로드합니다. 더 많은 정보는 상대 문서를 참조하십시오
사용자 정의 응용 프로그램 클래스를 만듭니다
public class AppContext extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this); // add this
}
}
Manifest.xml에 추가하십시오
<application
android:name=".AppContext"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
...
</application>
Styles.xml에서 기본 상위 테마를 교체하십시오
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
에게
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
다음과 같은 것을 얻을 수 있습니다.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
Chat21 SDK는 채팅에 대한 사용자 정의 동작 및 설정을 설정할 수있는 Chat.configuration 객체를 제공합니다.
Chat21 SDK의 새 인스턴스를 만들려면 자신만의 구성을 만들어야합니다 (Chat21 sdk chat.configuration.builder 사용)을 사용하여 메소드 Chat.initialize(configuration);
// optional
//enable persistence must be made before any other usage of FirebaseDatabase instance.
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
// mandatory
// it creates the chat configurations
ChatManager.Configuration mChatConfiguration =
new ChatManager.Configuration.Builder(<APP_ID>)
.firebaseUrl(<FIREBASE_DATABASE_URL>)
.storageBucket(<STORAGE_BUCKET>)
.build();
ChatManager.start(<CONTEXT>, mChatConfiguration, <LOGGED_USER>);
바꾸다:
<APP_ID> ;<FIREBASE_URL> ;<STORAGE_BUCKET> ;<CONTEXT> ;<LOGGED_USER> 현재 기록 된 사용자를 사용하여 Ichatuser의 인스턴스라고 가정합니다.Chatui를 사용하면 공통 UI 요소를 Chat21 SDK API에 빠르게 연결할 수 있습니다.
Chatui를 사용하면 활동과 내부 조각으로 채팅을 시작할 수 있습니다.
다음 명령어로 Chatui 구성 요소를 초기화하십시오
ChatUI.getInstance().setContext(this);
대화 목록이 포함 된 새로운 활동을 시작합니다.
ChatUI.getInstance().showConversationsListActivity();
내부 컨테이너가있는 조각을 만들어야합니다.
대화 목록이 표시되는이 컨테이너 내부에서 채팅이 시작됩니다.
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
이제 다음 방법으로 채팅을 표시 할 수 있습니다.
ChatUI.getInstance().openConversationsListFragment(getChildFragmentManager(), R.id.container);
com.android.support 내의 충돌
오류:
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
솔루션 :이 블록을 파일 하단에서 복사 /project/app/build.gradle
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '26.1.0'
}
}
}
}
멀티 덱스
오류:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
솔루션 : /project/app/build.gradle 의 내부에 multiDexEnabled true 추가했는지 확인하십시오.
이 블록을 사용자 정의 응용 프로그램 클래스 내부에 복사하십시오
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
주제
오류:
RuntimeException: Unable to start activity ComponentInfo{my.sample.package.myapplication/chat21.android.ui.conversations.activities.ConversationListActivity}: java.lang.IllegalStateException:
This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
해결책 : 스타일 섹션을 참조하십시오
응용 프로그램 이름 예외 :
오류:
/android/MyApp/app/src/main/AndroidManifest.xml:30:9 Error:
Attribute application@label value=(@string/application_name) from AndroidManifest.xml:30:9
is also present at {Library Name} value=(@string/app_name)
Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:26:5 to override
솔루션 : tools:replace="android:label" Chat21 SDK 앱 이름 및 기본 아이콘을 무시하려면 :
```
<application
android:name=".AppContext"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:label, android:icon"> <!-- add this -->
. . .
</application>
```
이 안내서를 따라 자신의 라이브러리를 JCenter에 배포하십시오.