Home > Net >  App crash when i use VideoUIKit-Android Agora
App crash when i use VideoUIKit-Android Agora

Time:11-08

when i build smaple project , app has been crashed when i see logcat , i see this: 90-30676/io.agora.agora_android_uikit E/agora.io: jni_generator_helper.h: (line 131): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

what do i do ?

My code:

package io.agora.agora_android_uikit

import android.Manifest
import android.graphics.Color
import android.os.Bundle
import android.view.ViewGroup
import android.widget.Button
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import io.agora.agorauikit_android.AgoraButton
import io.agora.agorauikit_android.AgoraConnectionData
import io.agora.agorauikit_android.AgoraSettings
import io.agora.agorauikit_android.AgoraVideoViewer
import io.agora.agorauikit_android.requestPermission
import io.agora.rtc2.Constants

private const val PERMISSION_REQ_ID = 22
private val REQUESTED_PERMISSIONS = arrayOf<String>(
    Manifest.permission.RECORD_AUDIO,
    Manifest.permission.CAMERA,
    Manifest.permission.WRITE_EXTERNAL_STORAGE
)

@ExperimentalUnsignedTypes
class MainActivity : AppCompatActivity() {
    var agView: AgoraVideoViewer? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        try {
            agView = AgoraVideoViewer(
                this, AgoraConnectionData("*******"),

            )
        } catch (e: Exception) {
            println("Could not initialise AgoraVideoViewer. Check your App ID is valid. ${e.message}")
            return
        }
        val set = FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT
        )

        this.addContentView(agView, set)

        if (AgoraVideoViewer.requestPermission(this)) {
            agView!!.join("test", role = Constants.CLIENT_ROLE_BROADCASTER)
        } else {
            val joinButton = Button(this)
//            [email protected](java.lang.Runnable {
            runOnUiThread {
                Runnable { joinButton.text = "Allow Camera and Microphone, then click here" }
            }
//            })
            joinButton.setOnClickListener {
                if (AgoraVideoViewer.requestPermission(this)) {
//                    (joinButton.parent as ViewGroup).removeView(joinButton)
                    agView!!.join("test", role = Constants.CLIENT_ROLE_BROADCASTER)
                }
            }
//            joinButton.setBackgroundColor(Color.GREEN)
//            joinButton.setTextColor(Color.RED)
            this.addContentView(
                joinButton,
                FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 300)
            )
        }
    }

i want to solve my issue

CodePudding user response:

Please wrap with function and make annotations there instead of mentioning in the main content view and wrap using UI thread.And refer sample github agora sdk github for reference - https://github.com/AgoraIO-Community/VideoUIKit-Android

  • Related