I'm trying to show a presentation into a virtual display on Android 12

742 views Asked by At

im trying to show a presentation that contains a video inside a virtual display i added a listener on the virtual display


private val mDisplayListener: DisplayManager.DisplayListener = object :        DisplayManager.DisplayListener {
private var mNewDisplayAdded = false
private var mCurrentDisplayId = -1
private var mPresentation: DataInjection? = null
override fun onDisplayAdded(i: Int) {
    Log.d(TAG, "onDisplayAdded id=$i")
    if (!mNewDisplayAdded && mCurrentDisplayId == -1) {
        mNewDisplayAdded = true
        mCurrentDisplayId = i
    }
}
override fun onDisplayRemoved(i: Int) {
    Log.d(TAG, "onDisplayRemoved id=$i")
    if (mCurrentDisplayId == i) {
        mNewDisplayAdded = false
        mCurrentDisplayId = -1
        if (mPresentation != null) {
            mPresentation!!.dismiss()
            mPresentation = null
        }
    }
}
override fun onDisplayChanged(i: Int) {
    Log.d(TAG, "onDisplayChanged id=$i")
    if (mCurrentDisplayId == i) {
        if (mNewDisplayAdded) {
            // create a presentation
            mNewDisplayAdded = false
            val display: Display = mDisplayManager!!.getDisplay(i)
            mPresentation = DataInjection(this@MainActivity, display)
            mPresentation!!.show()
        }
    }
}`

it did work on android 10 but when i changed to android 12 the application crashes once i click on the start button with this error

Unable to add window android.view.ViewRootImpl$W@b213c0 -- the specified display can not be found
                                                                                                        at android.view.ViewRootImpl.setView(ViewRootImpl.java:1187)

I've tried to show a presentation inside a virtual display it did work on android 10 but it didn't in android 12

0

There are 0 answers