logo
当前页

快速开始

准备环境

在开始集成音视频 UIKit 前,请确保开发环境满足以下要求:

  • Android Studio 2020.3.1 或以上版本。
  • Android SDK 25、Android SDK Build-Tools 25.0.2、Android SDK Platform-Tools 25.x.x 或以上版本。
  • Android 4.4 或以上版本,且支持音视频的 Android 设备。
  • Android 设备已经连接到 Internet。

前提条件

实现流程

集成 SDK

  1. 添加 jitpack 配置。

根据您的 Android Gradle 插件版本,选择对应的实现步骤。

  1. 修改您的 app 级别的 build.gradle 文件。
Untitled
dependencies {
    ...
    implementation 'com.github.ZEGOCLOUD:zego_uikit_prebuilt_call_android:+' 
}
1
Copied!

使用 ZegoUIKitPrebuiltCallFragment

声明 userIDuserNamecallID,用于创建通话。

Note
  • userIDcallID 只能包含数字、字母和下划线(_)。
  • 使用相同 callID 的用户可以连接到同一个通话。
  • UIKit 默认语言为英文,如需修改为中文,请修改 ZegoUIKitPrebuiltCallConfig.zegoCallText
Java
Kotlin
public class CallActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_call);

        addCallFragment();
    }

    public void addCallFragment() {
        long appID = yourAppID;
        String appSign = yourAppSign;

        String callID = callID;
        String userID = userID;
        String userName = userName;

        // 您也可以使用 GroupVideo/GroupVoice/OneOnOneVoice 来进行更多类型的呼叫。
        ZegoUIKitPrebuiltCallConfig config = ZegoUIKitPrebuiltCallConfig.oneOnOneVideoCall();
        // 设置语言为中文
        config.zegoCallText = new ZegoCallText(ZegoUIKitLanguage.CHS);
        ZegoUIKitPrebuiltCallFragment fragment = ZegoUIKitPrebuiltCallFragment.newInstance(
            appID, appSign, userID, userName,callID,config);

        getSupportFragmentManager().beginTransaction()
            .replace(R.id.fragment_container, fragment)
            .commitNow();
    }
}
1
Copied!
class CallActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_call)
        addCallFragment()
    }

    private fun addCallFragment() {
        val appID: Long = yourAppID
        val appSign: String = yourAppSign
        val callID: String = callID
        val userID: String = userID
        val userName: String = userName

        // 您也可以使用 GroupVideo/GroupVoice/OneOnOneVoice 来进行更多类型的呼叫。
        val config = ZegoUIKitPrebuiltCallConfig.oneOnOneVideoCall()
        //  设置语言为中文
        config.zegoCallText = ZegoCallText(ZegoUIKitLanguage.CHS);
        val fragment = ZegoUIKitPrebuiltCallFragment.newInstance(
            appID, appSign, userID, userName,callID, config
        )
        supportFragmentManager.beginTransaction()
            .replace(R.id.fragment_container, fragment)
            .commitNow()
    }
}
1
Copied!

修改自动生成的 activity_call.xml 文件:

Untitled
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/fragment_container"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

</androidx.constraintlayout.widget.ConstraintLayout>
1
Copied!

现在,您可以启动 CallActivity 进行音视频通话。

运行和测试

至此,您已经完成了所有步骤!

在 Android Studio 上点击 Run 即可在设备上运行和测试您的 App。

相关指南

资源