简体   繁体   English

如何在活动中(或在活动中)运行 Android Dream 服务?

[英]How do I run an Android Dream Service as (or within) an Activity?

I have a perfectly functioning DreamService that I want to use within my main activity along with an extra button so that the user can access settings (Android TV appears to be missing the daydream settings icon as far as I can tell).我有一个功能完美的 DreamService,我想在我的主要活动中使用它以及一个额外的按钮,以便用户可以访问设置(据我所知,Android TV 似乎缺少白日梦设置图标)。

Is there an easy way this could be done that would specifically avoid duplication of code?有没有一种简单的方法可以做到这一点,特别是避免代码重复?

Sure, just take the views you created for your service and put them in an activity instead.当然,只需将您为服务创建的视图放入活动中即可。 Make sure your views can work without a direct dependency on the service.确保您的视图可以在不直接依赖于服务的情况下工作。

You can invoke the DayDream like this -您可以像这样调用 DayDream -

Intent intentDream = new Intent(Intent.ACTION_MAIN);
intentDream.setClassName("com.android.systemui", "com.android.systemui.Somnambulator");
startActivity(intentDream);

Hope this helps.希望这可以帮助。

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

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