gpt4 book ai didi

android - 如果应用程序在启动时运行,如何使屏幕不休眠?

转载 作者:搜寻专家 更新时间:2023-11-01 08:24:19 25 4
gpt4 key购买 nike

我有必须在设备启动时启动的应用程序。它运行良好,但问题是当应用程序完成启动时,屏幕已经变暗了。怎样才能让它不睡着呢?我的接收器:

<receiver
android:enabled="true"
android:exported="true"
android:name=".view.receivers.BootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />

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


public class BootReceiver extends BroadcastReceiver {

private final static String LOG_TAG = BootReceiver.class.getSimpleName();

@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Log.i(LOG_TAG, "Loading after booting...");
Intent startCalendarActivityIntent = new Intent(context, CalendarActivity.class);
startCalendarActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startCalendarActivityIntent);
} else {
Log.e(LOG_TAG, "Error while restarting after boot.");
}
}
}

在此设备上是 Android 6.0。

最佳答案

您可以使用 wakelocks ,这需要一定的权限,或者你可以在你的 onCreate 方法中放置一个标志,根据 docs不需要许可。

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

唤醒锁文档给出了上面的例子。

关于android - 如果应用程序在启动时运行,如何使屏幕不休眠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46829301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com