1

嗨,当手机进入睡眠模式(即屏幕关闭模式)时,我需要显示屏幕。我使用了daydream,但问题是,它只能在充电时工作!

但我的要求是,即使手机进入睡眠模式(不充电),我也需要显示屏幕。

这是我尝试过的代码

import android.service.dreams.DreamService;
import android.widget.TextView;

public class MyDreamService extends DreamService {
    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();

        // Allow user touch
        setInteractive(true);

        // Hide system UI
        setFullscreen(true);

        // Set the dream layout

        setContentView(R.layout.activity_dream);
        TextView text = (TextView) findViewById(R.id.textView);
        text.setText("Hello DayDream world!!");

    }
} 

安卓清单.xml:

 <service
        android:name=".MyDreamService"
        android:exported="true"
        android:label="DayDreams">
        <intent-filter>
            <action android:name="android.service.dreams.DreamService" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </service>
4

1 回答 1

0

我自己回答。可以关闭设备,但应用程序必须通过 API 实现设备管理员功能:设备管理

在这个 API 中有一个 locknow() 函数可以做我想做的事。

无论如何,这是为了扩展 android 硬件和安全功能,任何人都不太可能想以这种方式控制设备。

我想要的是能够通过一个简单的手势来锁定设备。因为我不想创建自己的设备管理器类,所以我检查是否安装了免费应用程序“lockScreen”并启动它。这是做我想做的事的捷径和简单的方法。这个应用程序必须注册为设备管理器,所以它已经实现了这个类。可以从市场上免费获得它。

于 2017-04-05T09:40:43.327 回答