In Android, How To Change The Settings Of Daydream From Code?
Solution 1:
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:
publicvoidonSettingsButtonClick(View v) {
Intent intent;
if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR2) {
intent = newIntent(Settings.ACTION_DREAM_SETTINGS);
} else {
intent = newIntent(Settings.ACTION_DISPLAY_SETTINGS);
}
startActivity(intent);
}
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:
<serviceandroid:name="some.package.SomeDaydream"android:exported="true"android:icon="@drawable/ic_launcher"android:label="@string/app_name" ><intent-filter><actionandroid:name="android.service.dreams.DreamService" /><categoryandroid:name="android.intent.category.DEFAULT" /></intent-filter><meta-dataandroid:name="android.service.dream"android:resource="@xml/dream_info" /></service>
When targeting api level 21 and above, you must declare the service in your manifest file with the BIND_DREAM_SERVICE permission. For example:
android:permission="android.permission.BIND_DREAM_SERVICE">
Then, in /res/xml/
, add dream_info.xml
:
<?xml version="1.0" encoding="utf-8"?><dreamxmlns:android="http://schemas.android.com/apk/res/android"android:settingsActivity="some.package/.SomeActivity" />
I have an example Daydream here that shows this behaviour (in both directions).
Post a Comment for "In Android, How To Change The Settings Of Daydream From Code?"