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

只谈情不闲聊 提交于 2020-01-05 09:14:30

问题


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

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.

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. Also note that I do have an app title set in the Manifest, but that is not being shown here. 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?

Tested on Android TV API 26, 27, as Picture-in-Picture is only available since Oreo.


回答1:


If you implement MediaSession, the title will appear. The system evaluates the MediaSession similar to how notifications with MediaSession work on phones.

There is an activity that demonstrates how MediaSession can affect PIP actions in the android-PictureInPicture sample. 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);


来源:https://stackoverflow.com/questions/47219596/how-to-set-the-icon-and-title-on-android-tv-home-screen-for-the-currently-runnin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!