fix: lock screen flags are not permanent
This commit is contained in:
parent
5820111341
commit
831e1d49a3
@ -23,14 +23,12 @@
|
||||
<activity
|
||||
android:name=".activities.MainActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask"
|
||||
android:launchMode="singleTop"
|
||||
android:taskAffinity=""
|
||||
android:theme="@style/LaunchTheme"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:showWhenLocked="true"
|
||||
android:turnScreenOn="true">
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
||||
the Android process has started. This theme is visible to the user
|
||||
while the Flutter UI initializes. After that, this theme continues
|
||||
|
@ -34,6 +34,7 @@ class MainActivity : FlutterActivity() {
|
||||
Log.d(TAG, "onCreate started")
|
||||
wasPhoneLocked = intent.getBooleanExtra("wasPhoneLocked", false)
|
||||
Log.d(TAG, "Was phone locked at start: $wasPhoneLocked")
|
||||
updateLockScreenFlags(intent)
|
||||
handleIncomingCallIntent(intent)
|
||||
}
|
||||
|
||||
@ -42,9 +43,39 @@ class MainActivity : FlutterActivity() {
|
||||
setIntent(intent)
|
||||
wasPhoneLocked = intent.getBooleanExtra("wasPhoneLocked", false)
|
||||
Log.d(TAG, "onNewIntent, wasPhoneLocked: $wasPhoneLocked")
|
||||
updateLockScreenFlags(intent)
|
||||
handleIncomingCallIntent(intent)
|
||||
}
|
||||
|
||||
private fun updateLockScreenFlags(intent: Intent?) {
|
||||
val isIncomingCall = intent?.getBooleanExtra("isIncomingCall", false) ?: false
|
||||
if (isIncomingCall && wasPhoneLocked) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
||||
setShowWhenLocked(true)
|
||||
setTurnScreenOn(true)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
window.addFlags(
|
||||
android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
|
||||
android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|
||||
)
|
||||
}
|
||||
Log.d(TAG, "Enabled showWhenLocked and turnScreenOn for incoming call")
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
||||
setShowWhenLocked(false)
|
||||
setTurnScreenOn(false)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
window.clearFlags(
|
||||
android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
|
||||
android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|
||||
)
|
||||
}
|
||||
Log.d(TAG, "Disabled showWhenLocked and turnScreenOn for normal usage")
|
||||
}
|
||||
}
|
||||
|
||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
Log.d(TAG, "Configuring Flutter engine")
|
||||
|
Loading…
Reference in New Issue
Block a user