android CRASH 中的 Agora 屏幕共享
Posted
技术标签:
【中文标题】android CRASH 中的 Agora 屏幕共享【英文标题】:Agroa screen sharing in android CRASH 【发布时间】:2020-07-21 11:43:39 【问题描述】:示例代码:- 当我实现了从 Agora 官方网站链接 https://docs.agora.io/en/Video/screensharing_android?platform=Android 获得的以下代码时
我在 Android 9 上运行此代码。
MediaProjectionManager projectManager = (MediaProjectionManager) mContext.getSystemService(
Context.MEDIA_PROJECTION_SERVICE);
// Create the intent for screen capture. Call the startActivityForResult method to use the sharing function.
Intent intent = projectManager.createScreenCaptureIntent();
startActivityForResult(intent);
MediaProjection projection;
VirtualDisplay display;
// Override and implement the onActivityResult method of the Activity where you just called startActivityForResult.
@Override
onActivityResult(int requestCode, int resultCode, Intent resuleData)
projection = projectManager.getMediaProjection(resultCode, resultData);
display = projection.createVirtualDisplay(name, width, height, dpi, flags, surface, callback, handler);
// The texture retrieved from the Surface will be sent by the SDK.
rtcEngine.pushExternalVideoFrame(new AgoraVideoFrame(...));
// Stop screen sharing.
projection.stop();
当我运行这段代码时,我在这一行遇到了以下崩溃:- projection = projectManager.getMediaProjection(resultCode, resultData);
崩溃:-
java.lang.RuntimeException: Failure delivering result ResultInfowho=null, request=8899, result=-1, data=Intent (has extras) to activity com.fantka_live/com.fantka_live.ui.activity.agora_live_stream_module.LiveActivity: java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
at android.app.ActivityThread.deliverResults(ActivityThread.java:4846)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4887)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2017)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7403)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
at android.os.Parcel.createException(Parcel.java:2071)
at android.os.Parcel.readException(Parcel.java:2039)
at android.os.Parcel.readException(Parcel.java:1987)
at android.media.projection.IMediaProjection$Stub$Proxy.start(IMediaProjection.java:231)
at android.media.projection.MediaProjection.<init>(MediaProjection.java:58)
at android.media.projection.MediaProjectionManager.getMediaProjection(MediaProjectionManager.java:104)
【问题讨论】:
【参考方案1】:您可以参考这个共享屏幕演示代码:https://github.com/AgoraIO/Advanced-Video/tree/master/Android/sample-switch-external-video
【讨论】:
我已经完成了这个存储库,顺便谢谢你还有其他解决方案吗? 这个怎么样:github.com/AgoraIO/Advanced-Video/tree/dev/win-screenshare/…以上是关于android CRASH 中的 Agora 屏幕共享的主要内容,如果未能解决你的问题,请参考以下文章
在 android agora rtc sdk 中启用音频方法问题