首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >公共虚拟显示有黑色屏幕

公共虚拟显示有黑色屏幕
EN

Stack Overflow用户
提问于 2022-09-11 15:32:53
回答 1查看 258关注 0票数 1

我运行了这个例子:https://github.com/android/media-samples/tree/main/ScreenCapture

并将显示更改为公共显示,以便我可以使用scrcpy访问它:

代码语言:javascript
运行
复制
mVirtualDisplay = mMediaProjection.createVirtualDisplay("ScreenCapture",
                mSurfaceView.getWidth(), mSurfaceView.getHeight(), mScreenDensity,
                DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC,
                mSurface, null, null);

当我使用scrcpy打开显示时,我会得到一个完全黑色的屏幕,而在预览中它将正确显示。

为什么它在scrcpy中提供了一个黑色屏幕?

我假设这是因为显示不安全(警告:显示没有FLAG_SUPPORTS_PROTECTED_BUFFERS标志,镜像可以被限制),但普通应用程序无法创建安全的虚拟显示,因为权限仅针对系统应用程序。

有办法让它起作用吗?

EN

回答 1

Stack Overflow用户

发布于 2022-10-11 14:01:27

scrcpy显示一个黑色屏幕,因为在这个显示(您定义的显示)中,三个没有表示视图。请使用此代码在scrcpy上显示某些内容。

代码语言:javascript
运行
复制
import android.app.ActivityOptions;
import android.app.Presentation;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;

public class PresentationDisplay extends Presentation {

    public PresentationDisplay(Context outerContext, Display display) {
        super(outerContext, display);
    }

    public PresentationDisplay(Context outerContext, Display display, int theme) {
        super(outerContext, display, theme);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about_ui);
        ActivityOptions options = ActivityOptions.makeTaskLaunchBehind();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            options.setLaunchDisplayId(getDisplay().getDisplayId());
        }

        Log.e("TAG", "DISPLAY_CATEGORY_PRESENTATION  " + getDisplay().getDisplayId());

    }
}

并使用它:

代码语言:javascript
运行
复制
  MediaRouter.RouteInfo route = ((MediaRouter) context.getSystemService(MEDIA_ROUTER_SERVICE)).getSelectedRoute(ROUTE_TYPE_LIVE_VIDEO);
        if (route != null) {
            PresentationDisplay secondaryDisplay = new PresentationDisplay(context,route.getPresentationDisplay());
            secondaryDisplay.show();
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73680519

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档