嗨,当手机进入睡眠模式(即屏幕关闭模式)时,我需要显示屏幕。我使用了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>