简体   繁体   English

如何在 Android TV 主屏幕上为当前正在运行的任务设置图标和标题

[英]How to set the icon and title on Android TV home screen for the currently running task

I have enabled picture-in-picture mode for an Android TV app based on this guide: https://developer.android.com/guide/topics/ui/picture-in-picture.html我已根据本指南为 Android TV 应用启用画中画模式: https : //developer.android.com/guide/topics/ui/picture-in-picture.html

When I enter PiP mode, and navigate to the home screen of the Android home screen, it shown at the top the currently running task (PiP window) with an icon an title and options to Open and Close.当我进入画中画模式并导航到 Android 主屏幕的主屏幕时,它会在顶部显示当前正在运行的任务(画中画窗口),并带有图标、标题和打开和关闭选项。

在此处输入图片说明

I could not find any documentation on how to set the the title and the icon (but most importantly the title).我找不到任何关于如何设置标题和图标(但最重要的是标题)的文档。 I have tried setting the ActivityManager.TaskDescription but without any luck.我试过设置ActivityManager.TaskDescription但没有任何运气。 Also note that I do have an app title set in the Manifest , but that is not being shown here.另请注意,我确实在 Manifest 中设置了应用程序标题,但此处未显示。 Also note that in the task switcher, the app title and icon is shown correctly.另请注意,在任务切换器中,应用程序标题和图标显示正确。

Any ideas how to set the (No title program) from the screenshot?任何想法如何从屏幕截图中设置(No title program)

Tested on Android TV API 26, 27, as Picture-in-Picture is only available since Oreo.在 Android TV API 26、27 上进行了测试,因为画中画仅在 Oreo 之后可用。

If you implement MediaSession, the title will appear.如果您实现 MediaSession,标题将出现。 The system evaluates the MediaSession similar to how notifications with MediaSession work on phones.系统评估 MediaSession 的方式类似于 MediaSession 通知在手机上的工作方式。

There is an activity that demonstrates how MediaSession can affect PIP actions in the android-PictureInPicture sample.有一个活动演示了 MediaSession 如何影响 android-PictureInPicture 示例中的 PIP 操作。 This is a bug in the sample, thank you for logging it.这是示例中的一个错误,感谢您记录它。

To get the title to appear, you will need to update the meta data on the media session.要显示标题,您需要更新媒体会话中的元数据。

MediaMetadataCompat metadata = new MediaMetadataCompat.Builder()
            .putString(
                 MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, 
                "Big Buck Bunny")
            ...
            .build();
mSession.setMetadata(metadata);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM