简体   繁体   English

Android:应用程序中的DayDream

[英]Android: DayDream in Application

I'm developing application in which I'm using DreamService. 我正在开发我正在使用DreamService的应用程序。 But built-in options only give start daydreaming while charging and docking. 但是内置选项只能在充电和对接时开始做白日梦。 Is there any solution to invoke daydreaming during executing application( while device is inactive for a while, say, 5 sec)? 是否有任何解决方案在执行应用程序期间调用白日梦(而设备暂时不活动,比如5秒)?

Answer is a year late and doesn't address the inactivity for 5 sec issue, but still might be useful... 答案迟了一年,并没有解决5秒问题的不活动,但仍然可能有用......

Add the following DreamNow.java file to your project and extend your Activity with the DreamNow class. 将以下DreamNow.java文件添加到项目中,并使用DreamNow类扩展Activity。

import android.app.Activity;
import android.content.Intent;

/**
 * To use, replace "extends Activity" in your activity with "extends DreamNow".
 *
 * From the Google Android Blog Daydream example.
 */
public class DreamNow extends Activity {
    @Override
    public void onStart() {
        super.onStart();
        final Intent intent = new Intent(Intent.ACTION_MAIN);

        try {
            // Somnabulator is undocumented--may be removed in a future version...
            intent.setClassName("com.android.systemui",
                                "com.android.systemui.Somnambulator");
            startActivity(intent);
            finish();

        } catch (Exception e) { /* Do nothing */ }
    }
}

DreamServiceService继承时,应该可以使用startService动态启动它们。

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

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