FullScreenIntent 在小米设备上不起作用。

huangapple go评论131阅读模式
英文:

FullScreenIntent not working on xiaomi devices

问题

我正在开发一个通话应用。我需要在收到推送通知后自动显示响铃界面。除了小米设备之外,一切正常。有时,小米设备的屏幕没有点亮。小米设备的秘密是什么?

小米设备上已经授予了所有权限:

  1. 后台进程:无限制
  2. 禁用电池优化
  3. 自动启动已启用

我在程序中使用了以下方法:

NotificationCompat.Builder()
 .setPriority(NotificationCompat.PRIORITY_HIGH)
 .setCategory(NotificationCompat.CATEGORY_CALL)
 .setFullScreenIntent(fullScreenPendingIntent, true)
 private fun showWhenLockedAndTurnScreenOn() {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
            setShowWhenLocked(true)
            setTurnScreenOn(true)
            val keyguardManager = getSystemService(KEYGUARD_SERVICE) as KeyguardManager
            keyguardManager.requestDismissKeyguard(this, null)
        } else {
            window.addFlags(
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
                        WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
                        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
                        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            )
        }
    }
  1. 清单文件中的权限:

对于活动:

 android:showOnLockScreen="true"

对于应用程序:

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />

对于小米设备,我是否遗漏了什么?

英文:

I am developing a calling app. I need to show the ringing screen automatically after receiving push notification. It works ok except xiaomi-devices. Sometimes, the screen is not switched on. What is the secret for xiaomi-devices?
All permissions on the xiaomi-device are granted:

  1. Background processes: no limit
  2. Disabled battery optimizations
  3. Autostart is on

What i use programmatically:

1.

NotificationCompat.Builder()
 .setPriority(NotificationCompat.PRIORITY_HIGH)
 .setCategory(NotificationCompat.CATEGORY_CALL)
 .setFullScreenIntent(fullScreenPendingIntent, true)
 private fun showWhenLockedAndTurnScreenOn() {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
            setShowWhenLocked(true)
            setTurnScreenOn(true)
            val keyguardManager = getSystemService(KEYGUARD_SERVICE) as KeyguardManager
            keyguardManager.requestDismissKeyguard(this, null)
        } else {
            window.addFlags(
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
                        WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
                        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
                        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            )
        }
    }
  1. Manifest permissions:

for activity:

 android:showOnLockScreen="true"

for app:

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />

What am I missing out for Xiaomi?

答案1

得分: 2

看起来这段代码有所帮助:

fun asquireWake() {
    val mPowerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
    val mWakeLock: PowerManager.WakeLock = mPowerManager.newWakeLock(
        PowerManager.SCREEN_BRIGHT_WAKE_LOCK or PowerManager.ACQUIRE_CAUSES_WAKEUP,
        "App:IncomingCall"
    )
    mWakeLock.acquire(1*60*1000L /*1 分钟*/)
}

我在显示通知之前编写了它。

英文:

it seems that this code helped:

  fun asquireWake() {
    val mPowerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
    val mWakeLock: PowerManager.WakeLock = mPowerManager.newWakeLock(
        PowerManager.SCREEN_BRIGHT_WAKE_LOCK or PowerManager.ACQUIRE_CAUSES_WAKEUP,
        "App:IncomingCall"
    )
    mWakeLock.acquire(1*60*1000L /*1 minute*/)
}

I writed it before showing the notification.

答案2

得分: 1

小米设备在锁屏上具有特定的权限,您需要手动启用此权限:

  1. 进入应用设置,选择其他权限

  2. 选择显示在锁屏上

  3. 在弹出窗口上选中始终允许

这个设置将确保您的应用在锁屏上显示全屏意图活动。

英文:

Xiaomi devices have a specific permission regarding full screen intents on the lock screen. You have to enable this permission manually:

  1. Go to app settings and select Other permissions:

FullScreenIntent 在小米设备上不起作用。

  1. Select Show on lock screen:

FullScreenIntent 在小米设备上不起作用。

  1. Check Always allow on the pop-up:

FullScreenIntent 在小米设备上不起作用。

This setting will ensure that your app displays full screen intent activities on the lock screen.

huangapple
  • 本文由 发表于 2023年3月7日 21:26:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75662575.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定