user3113441 user3113441 - 1 year ago 101
Android Question

In android, how to change the settings of Daydream from code?

I want to write a application which can change the daydream setting. It will require to set the my own dream as selected and also make the when to play option as "Either". Is that possible to implement this feature in the sdk version 19?

Answer Source

If you want to set the daydream for the user, you cannot do this. You can, however, open the system settings in the right location so that the user can select from installed daydreams.

You can provide a button to access Daydream Settings like so:

public void onSettingsButtonClick(View v) {
    Intent intent;
        intent = new Intent(Settings.ACTION_DREAM_SETTINGS);
    } else {
        intent = new Intent(Settings.ACTION_DISPLAY_SETTINGS);

This will take the user to either "Daydream Settings" or the "Display Settings" section of the device settings.

If you'd like the user to be able to go from the device settings to a specific activity for configuring your daydream, you can add the <meta-data/> tag here as an element of your Daydream service in your manifest:

        android:label="@string/app_name" >
            <action android:name="android.service.dreams.DreamService" />
            <category android:name="android.intent.category.DEFAULT" />
            android:resource="@xml/dream_info" />

When targeting api level 21 and above, you must declare the service in your manifest file with the BIND_DREAM_SERVICE permission. For example:


Then, in /res/xml/, add dream_info.xml:

<?xml version="1.0" encoding="utf-8"?>
<dream xmlns:android=""
    android:settingsActivity="some.package/.SomeActivity" />

I have an example Daydream here that shows this behaviour (in both directions).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download