3

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)?

AlexVogel
  • 10,601
  • 10
  • 61
  • 71
Forin
  • 1,549
  • 2
  • 20
  • 44

2 Answers2

2

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 */ }
    }
}
Keith Pinson
  • 1,725
  • 1
  • 14
  • 17
0

As DreamService inherits from Service it should be possible to dynamically start them by using startService.

adrianp
  • 2,491
  • 5
  • 26
  • 44
  • When I tried this, the `onStartCommand` method was called in the `DreamService` subclass but not the daydream lifecycle methods like `onAttachToWindow` and `onDreamingStarted`. – Michiyo Dec 11 '15 at 23:26