gpt4 book ai didi

android - 添加 list CAPTURE_VIDEO_OUTPUT 或 CAPTURE_SECURE_VIDEO_OUTPUT 时为什么会出错?

转载 作者:行者123 更新时间:2023-12-05 00:21:52 29 4
gpt4 key购买 nike

面对这样的问题。随着这段代码的实现,一个异常:

DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
int mDensity = displayMetrics.densityDpi;

        DisplayManager dM = (DisplayManager) getSystemService(ContextWrapper.DISPLAY_SERVICE);

ImageReader imR = ImageReader.newInstance(300, 300, PixelFormat.RGBA_8888, 2);


VirtualDisplay vD = dM.createVirtualDisplay("VladScreen", 300, 300, mDensity, imR.getSurface(), DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC);

异常(exception)情况如下:
 java.lang.SecurityException: Requires CAPTURE_VIDEO_OUTPUT or CAPTURE_SECURE_VIDEO_OUTPUT permission, or an appropriate MediaProjection token in order to create a screen sharing virtual display.
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.os.Parcel.readException(Parcel.java:1599)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.os.Parcel.readException(Parcel.java:1552)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.hardware.display.IDisplayManager$Stub$Proxy.createVirtualDisplay(IDisplayManager.java:484)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.hardware.display.DisplayManagerGlobal.createVirtualDisplay(DisplayManagerGlobal.java:377)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.hardware.display.DisplayManager.createVirtualDisplay(DisplayManager.java:537)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.hardware.display.DisplayManager.createVirtualDisplay(DisplayManager.java:529)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.hardware.display.DisplayManager.createVirtualDisplay(DisplayManager.java:480)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at com.example.novoseltsev.applicationpopupwindow.MainActivity.onCreate(MainActivity.java:106)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.app.Activity.performCreate(Activity.java:6237)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.app.ActivityThread.-wrap11(ActivityThread.java)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.os.Looper.loop(Looper.java:148)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at java.lang.reflect.Method.invoke(Native Method)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
09-27 04:03:30.321 7739-7739/com.example.novoseltsev.applicationpopupwindow W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
09-27 04:03:30.363 7739-11879/com.example.novoseltsev.applicationpopupwindow D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true

我了解它没有添加到许可 CAPTURE_VIDEO_OUTPUTCAPTURE_SECURE_VIDEO_OUTPUT .

但添加 manifest.xml 后异常仍然存在
<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT"/>

最佳答案

它是针对系统服务的,而不是针对第三方应用程序的。

https://developer.android.com/reference/android/hardware/display/DisplayManager.html#VIRTUAL_DISPLAY_FLAG_PUBLIC

创建一个不限于自有内容的公共(public)虚拟显示仅隐含地创建一个自动镜像显示。有关允许谁创建自动镜像显示的限制,请参阅 VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR。

https://developer.android.com/reference/android/hardware/display/DisplayManager.html#VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
……
创建自动镜像虚拟显示器需要 CAPTURE_VIDEO_OUTPUT 或 CAPTURE_SECURE_VIDEO_OUTPUT 权限。这些权限保留供系统组件使用,第三方应用程序不可用。或者,可以使用适当的 MediaProjection 来创建自动镜像虚拟显示器。

关于android - 添加 list CAPTURE_VIDEO_OUTPUT 或 CAPTURE_SECURE_VIDEO_OUTPUT 时为什么会出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39715812/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com