我正在开发一个应该在特殊情况下显示白日梦的应用程序,我到处搜索以找到一种通过我的 MainActivity 类启动白日梦服务的正确方法,但没有运气,
目前我正在使用以下代码来启动白日梦,实际上它可以工作,但我需要一个更好的解决方案,它为我提供了一种停止白日梦的方法。
public void startDayDream(){
final Intent intent = new Intent(Intent.ACTION_MAIN);
try {
// Somnabulator is undocumented--may be removed in a future version...
intent.setClassName("com.android.systemui",
"com.android.systemui.Somnambulator");
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
} catch (Exception e) { /* Do nothing */ }
}