简体   繁体   中英

Android: DayDream in Application

I'm developing application in which I'm using 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)?

Answer is a year late and doesn't address the inactivity for 5 sec issue, but still might be useful...

Add the following DreamNow.java file to your project and extend your Activity with the DreamNow class.

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动态启动它们。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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