【问题标题】:Activity Remains BLACK when launching under Doze Mode在打盹模式下启动时活动保持黑色
【发布时间】:2018-10-30 12:33:26
【问题描述】:

所以我有一个从服务启动的警报活动,并且在打盹模式下活动保持黑色,直到我将其关闭并再次打开。

现在,虽然屏幕是黑色的,但 视图是响应式的(如果我触摸它们,它们就会起作用)

如果我尝试截屏,我会突然看到活动,如果我关闭并再次打开屏幕,一切都会按预期工作

奇怪的视频:

Responsive black screen

Turn off, and on again

Trying to take a screenshot

这基本上是我启动活动的方式:

val builder = NotificationCompat.Builder(context, NotificationChannels.CHANNEL_ALARM_SERVICE)
...
// set intent
val alarmIntent = Intent(context, AlarmActivity::class.java)
alarmIntent.putExtra(IntentExtras.KEY_ID, alarm.id)
builder.setFullScreenIntent(PendingIntent.getActivity(context, RequestCodes.REQUEST_CODE_ALARM_ACTIVITY, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT), true)
...
startForeground(...)

这就是我在 Activity 的 onCreate 方法中解锁屏幕的方式

public class ScreenUnlockerUtil {

public static void unlockScreen(BaseActivity activity) {

    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
        // in addition to flags
        activity.setShowWhenLocked(true);
        activity.setTurnScreenOn(true);
        return;
    }


    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        KeyguardManager keyguardManager = (KeyguardManager) activity.getSystemService(KEYGUARD_SERVICE);
        if (keyguardManager != null) {
            keyguardManager.requestDismissKeyguard(activity, new KeyguardManager.KeyguardDismissCallback() {
                @Override
                public void onDismissError() {
                    super.onDismissError();
                    Timber.e("Keyguard Dismiss Error");
                }

                @Override
                public void onDismissSucceeded() {
                    super.onDismissSucceeded();
                    Timber.d("Keyguard Dismiss Success");
                }

                @Override
                public void onDismissCancelled() {
                    super.onDismissCancelled();
                    Timber.w("Keyguard Dismiss Cancelled");
                }
            });
        }
        return;
    }


}

我设法重现了这个问题

adb shell dumpsys deviceidle force-idle

我自然不能发布所有代码,但如果您需要任何东西,请告诉我。

谢谢!

【问题讨论】:

  • return 应该出现在O_MR1 检查中吗?

标签: android android-activity alarmmanager android-notifications android-doze


【解决方案1】:

从 if 语句中删除 return

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
    // in addition to flags
    activity.setShowWhenLocked(true);
    activity.setTurnScreenOn(true);
    //return;
}

【讨论】:

  • 它似乎仍在发生,但是当我连接到调试版本时从未发生过。
  • 通过调试连接意味着没有打盹模式,这可能是原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-06
  • 1970-01-01
  • 1970-01-01
  • 2015-10-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多