简体   繁体   English

为什么 Android 不退出打盹模式,尽管 FCM 中消息的优先级很高?

[英]Why Android does not exit DOZE mode, despite the high priority of the message in FCM?

I'm sending a data-message via FCM with HIGH priority.我正在通过 FCM 以高优先级发送数据消息。

curl -X POST -H "Authorization: Bearer ya29.c.b0AXv..." -H "Content-Type: application/json" -d '{
  "message": {
    "topic" : "mytopic",
    "data": {
      "message": "my_unique_data"
    },
    "android":{
      "priority":"high"
    },

  }
}' https://fcm.googleapis.com/v1/projects/myproject/messages:send

After receipt - I call a notification.收到后 - 我打电话通知。 If Android is active, this works.如果 Android 处于活动状态,则此方法有效。

But if the smartphone's screen is off, and the smartphone is stationary for a while, and I send the data message again, the notification doesn't show up until I little move the phone.但是,如果智能手机的屏幕关闭,并且智能手机静止了一段时间,然后我再次发送数据消息,则通知不会出现,直到我稍微移动手机。

I guess the Android is in DOZE mode, but the documentation states that a high-priority message FCM puts the smartphone out of this mode.我猜 Android 处于打盹模式,但文档指出高优先级消息 FCM 使智能手机退出此模式。

Help solve the problem, please.请帮忙解决问题。

There are 2 reasons this may be happening (from here ):发生这种情况有两个原因(从这里):

  1. There are high priority notification quotas for each app, and if you send too many of those notifications, the OS will de-prioritize them每个应用程序都有高优先级通知配额,如果您发送的通知数量过多,操作系统将取消它们的优先级
  2. Google requires that there is some kind of user interaction with the high-priority FCM messages (to prevent abuse by developers). Google 要求用户与高优先级 FCM 消息进行某种交互(以防止开发人员滥用)。 So, if you send "hidden" FCM notifications that, for example, show up in a silent notification channel, your app's quota will be de-prioritized.因此,如果您发送“隐藏”的 FCM 通知,例如,显示在静默通知通道中,您的应用程序的配额将被取消优先级。 Also, the user needs to either open the app, or click on the notification within some interval (I didn't see the actual time frame documented).此外,用户需要打开应用程序,或者在某个时间间隔内单击通知(我没有看到记录的实际时间范围)。 If they don't, it gets de-prioritized as well.如果他们不这样做,它也会被取消优先级。
  3. List item项目清单

So, it sounds like your app's FCM quota was de-prioritized, and you'll need to figure out which scenario applies因此,听起来您的应用的 FCM 配额已被取消优先级,您需要确定适用哪种情况

In general, you are correct, as stated in:一般来说,您是正确的,如下所述:

FCM is optimized to work with Doze and App Standby idle modes. FCM 已针对 Doze 和 App Standby 空闲模式进行了优化。 FCM high priority messages let you reliably wake your app to engage the user. FCM 高优先级消息让您能够可靠地唤醒您的应用以吸引用户。 In Doze or App Standby mode, the system delivers the message and gives the app temporary access to network services and partial wakelocks, then returns the device or app to the idle state.在 Doze 或 App Standby 模式下,系统传递消息并让应用程序临时访问网络服务和部分唤醒锁,然后将设备或应用程序返回到空闲 state。 For time sensitive, user-visible notifications, consider using high priority messages to enable delivery in Doze mode.对于时间敏感、用户可见的通知,请考虑使用高优先级消息以在打盹模式下启用传递。 High priority messages are expected to result in notifications.高优先级消息预计会导致通知。 See FCM's guidance on high priority messages for more information.有关详细信息,请参阅 FCM 关于高优先级消息的指南。

How ever, they also mention:然而,他们也提到:

lmost all apps should be able to support Doze by managing network connectivity, alarms, jobs, and syncs properly, and by using FCM messages.几乎所有应用程序都应该能够通过正确管理网络连接、警报、作业和同步以及使用 FCM 消息来支持打盹。 For a narrow set of use cases, this might not be sufficient.对于一组狭窄的用例,这可能还不够。 For such cases, the system provides a configurable list of apps that are partially exempt from Doze and App Standby optimizations.对于这种情况,系统提供了一个可配置的应用程序列表,这些应用程序部分地免于打盹和应用程序待机优化。 An app that is partially exempt can use the network and hold partial wake locks during Doze and App Standby.部分豁免的应用程序可以在打盹和应用程序待机期间使用网络并保持部分唤醒锁定。 However, other restrictions still apply to the app, just as they do to other apps.但是,其他限制仍然适用于该应用程序,就像它们对其他应用程序一样。 For example, the app's jobs and syncs are deferred (on API level 23 and below), and its regular AlarmManager alarms do not fire.例如,应用程序的作业和同步被延迟(在 API 级别 23 及以下),并且其常规 AlarmManager 警报不会触发。 An app can check whether it is currently on the exemption list by calling isIgnoringBatteryOptimizations().应用程序可以通过调用 isIgnoringBatteryOptimizations() 来检查它当前是否在豁免列表中。

Sometimes, OEM's also change the behavior of doze mode which creates bit different functionality than those stated in Google's documentation.有时,OEM 也会更改打盹模式的行为,从而创建与 Google 文档中所述的功能略有不同的功能。 So I'd suggest following their tip in the documents:所以我建议按照他们在文档中的提示:

Users can manually configure the list of exempted apps in Settings > Battery > Battery Optimization.用户可以在设置 > 电池 > 电池优化中手动配置豁免应用列表。 Alternatively, the system provides ways for apps to ask users to exempt them: Most apps should invoke an intent that contains the ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS.或者,系统为应用程序提供请求用户豁免它们的方法:大多数应用程序应调用包含 ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS 的意图。 Apps that satisfy an acceptable use case can instead invoke an intent that contains the ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS intent action to let the user add the app to the exemption list directly, without going to system settings.满足可接受用例的应用程序可以改为调用包含 ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS 意图操作的意图,让用户直接将应用程序添加到豁免列表,而无需进入系统设置。 Note: Google Play policies prohibit apps from requesting direct exemption from Power Management features in Android 6.0+ (Doze and App Standby) unless the core function of the app is adversely affected.注意:Google Play 政策禁止应用请求直接免除 Android 6.0+(打盹和应用待机)中的电源管理功能,除非应用的核心 function 受到不利影响。 An app can check whether it is currently on the exemption list by calling isIgnoringBatteryOptimizations().应用程序可以通过调用 isIgnoringBatteryOptimizations() 来检查它当前是否在豁免列表中。

I believe this should fix your problem我相信这应该可以解决您的问题

Doc - https://developer.android.com/training/monitoring-device-state/doze-standby文档 - https://developer.android.com/training/monitoring-device-state/doze-standby

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使使用高优先级消息,Android 应用程序也不会从打盹模式中唤醒 - Android app not waking up from doze mode even with High priority Message 如何使用 FCM 在 Android 上发送高优先级收件箱样式通知? - How do I send a high priority inbox style notification on Android using FCM? 在打盹模式下维护 window 的持续时间是多少? - What is the duration of a maintenance window during doze mode? FCM 通知标题仍为“FCM 消息” - FCM notification title remains "FCM Message" 为什么 dev_appserver.py 没有抛出错误就退出了? - Why does dev_appserver.py exit without throwing errors? 无法为我的应用程序(SDK Android 5.0)的通知添加 Firebase FCM。 为什么? - Can't add Firebase FCM for notifications on my app (SDK Android 5.0). Why? FCM BigQuery - 未返回 MESSAGE_DELIVERED 记录 - FCM BigQuery - No MESSAGE_DELIVERED records returned 触发少数高优先级通知后的 Firebase 推送通知延迟 - Firebase push notification delay after triggering few high priority notifications Firebase Notification Composer:如何将通知优先级设置为“高”? - Firebase Notification Composer: How to set notification priority to "high"? 在发布模式下使用 firebase auth 在 Android 上登录失败。 DEBUG 模式正常。 代码=10,消息=10,mPendingCredential=null - Failure to login using firebase auth on Android in release mode. DEBUG mode is OK. Code=10, message=10,mPendingCredential=null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM