英文:
FullScreenIntent not working on xiaomi devices
问题
我正在开发一个通话应用。我需要在收到推送通知后自动显示响铃界面。除了小米设备之外,一切正常。有时,小米设备的屏幕没有点亮。小米设备的秘密是什么?
小米设备上已经授予了所有权限:
- 后台进程:无限制
- 禁用电池优化
- 自动启动已启用
我在程序中使用了以下方法:
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
)
}
}
- 清单文件中的权限:
对于活动:
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:
- Background processes: no limit
- Disabled battery optimizations
- 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
)
}
}
- 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
小米设备在锁屏上具有特定的权限,您需要手动启用此权限:
-
进入应用设置,选择其他权限:
-
选择显示在锁屏上:
-
在弹出窗口上选中始终允许:
这个设置将确保您的应用在锁屏上显示全屏意图活动。
英文:
Xiaomi devices have a specific permission regarding full screen intents on the lock screen. You have to enable this permission manually:
- Go to app settings and select Other permissions:
- Select Show on lock screen:
- Check Always allow on the pop-up:
This setting will ensure that your app displays full screen intent activities on the lock screen.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论