See Also: DreamService Members
Extend this class to implement a custom dream (available to the user as a "Daydream").
xml Example
<service android:name=".MyDream" android:exported="true" android:icon="@drawable/my_icon" android:label="@string/my_dream_label" > <intent-filter> <action android:name="android.service.dreams.DreamService" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <!-- Point to additional information for this dream (optional) --> <meta-data android:name="android.service.dream" android:resource="@xml/my_dream" /> </service>
xml Example
<dream xmlns:android="http://schemas.android.com/apk/res/android" android:settingsActivity="com.example.app/.MyDreamSettingsActivity" />
java Example
public class MyDream extends DreamService { @Override public void onAttachedToWindow() { super.onAttachedToWindow(); // Exit dream upon user touch setInteractive(false); // Hide system UI setFullscreen(true); // Set the dream layout setContentView(R.layout.dream); } }
xml Example
<service android:name=".MyDream" android:exported="true" android:icon="@drawable/my_icon" android:label="@string/my_dream_label" android:permission="android.permission.BIND_DREAM_SERVICE"> <intent-filter> <action android:name=”android.service.dreams.DreamService” /> <category android:name=”android.intent.category.DEFAULT” /> </intent-filter> </service>
Dreams are interactive screensavers launched when a charging device is idle, or docked in a desk dock. Dreams provide another modality for apps to express themselves, tailored for an exhibition/lean-back experience.
The DreamService lifecycle is as follows:
In addition, onCreate and onDestroy (from the Service interface) will also be called, but initialization and teardown should be done by overriding the hooks above.
To be available to the system, your DreamService should be declared in the manifest as follows:
If specified with the <meta-data> element, additional information for the dream is defined using the NoType:android/R$styleable;Href=../../../../reference/android/R.styleable.html#Dream element in a separate XML file. Currently, the only addtional information you can provide is for a settings activity that allows the user to configure the dream behavior. For example:
res/xml/my_dream.xml
This makes a Settings button available alongside your dream's listing in the system settings, which when pressed opens the specified activity.
To specify your dream layout, call DreamService.SetContentView(Android.Views.View), typically during the DreamService.OnAttachedToWindow callback. For example:
When targeting api level 21 and above, you must declare the service in your manifest file with the NoType:android/Manifest$permission;Href=../../../../reference/android/Manifest.permission.html#BIND_DREAM_SERVICE permission. For example: