无法在锁定屏幕前获取我的 Activity

Can't get my Activity in front of the lock screen

我想把我的activity放在锁屏前。我添加了我在 Internet 上看到的任何内容作为在锁定屏幕上打印 activity 的标志。

但在某些设备上我无法实现这一点:华为、小米等

public class MyActivity extends AppCompatActivity() {

private void adjustScreen() {
 
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS | 
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
        
        
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
    setShowWhenLocked(true);
    setTurnScreenOn(true);
        
    (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE)
    .requestDismissKeyguard(this, null);
  }
}

清单:

 <activity
   android:name=".MyActivity"
   android:configChanges="locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|screenSize|fontScale"
   android:excludeFromRecents="true"
   android:exported="true"
   android:launchMode="singleTask"
   android:screenOrientation="portrait"
   android:showOnLockScreen="true"
   android:showWhenLocked="true"
   android:turnScreenOn="true"/>

它只适用于这些行:

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