在android中,如何通过代码更改Daydream的设置? [英] In android, how to change the settings of Daydream from code?

查看:175
本文介绍了在android中,如何通过代码更改Daydream的设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个可以更改白日梦设置的应用程序.这将需要将我自己的梦想设置为选中状态,并且将何时玩的选项设置为任意".可以在sdk 19版中实现此功能吗?

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?

推荐答案

如果要为用户设置白日梦,则无法执行此操作.但是,您可以在正确的位置打开系统设置,以便用户可以从已安装的白日梦中进行选择.

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.

您可以提供一个按钮来访问Daydream设置,如下所示:

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

public void onSettingsButtonClick(View v) {
    Intent intent;
    if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR2) {
        intent = new Intent(Settings.ACTION_DREAM_SETTINGS);
    } else {
        intent = new Intent(Settings.ACTION_DISPLAY_SETTINGS);
    }
    startActivity(intent);
}

这会将用户带到设备设置的白日梦设置"或显示设置"部分.

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

如果您希望用户能够从设备设置转到用于配置白日梦的特定活动,则可以在此处将<meta-data/>标记添加为清单中Daydream服务的元素:

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:

    <service
        android:name="some.package.SomeDaydream"
        android:exported="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.service.dreams.DreamService" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data
            android:name="android.service.dream"
            android:resource="@xml/dream_info" />
    </service>

定位api级别21和更高级别时,您必须在具有BIND_DREAM_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">

然后在/res/xml/中添加dream_info.xml:

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

我有一个示例Daydream 在此显示了此行为(双向).

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

这篇关于在android中,如何通过代码更改Daydream的设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆