gpt4 book ai didi

android - 手机休眠时的 BroadcastReceiver 行为

转载 作者:行者123 更新时间:2023-11-29 21:44:24 25 4
gpt4 key购买 nike

我不太确定在 list 中注册并通过 PackageManager 启用的 BroadcastReceiver 的行为是什么时候手机处于 sleep 状态。出现这个问题是因为我需要一个注册接收器来接收来自 WifiManager

的广播
<receiver
android:name=".receivers.ScanResultsReceiver"
android:enabled="false" >
<intent-filter>
<action android:name="android.net.wifi.SCAN_RESULTS" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
</intent-filter>
</receiver>

但我想知道的是(如文档链接或谷歌群组中的一些权威帖子)是哪些广播保证在电话睡着时唤醒接收器(如单独放置一段时间)并在 onReceive() 运行时保持手机唤醒(当然时间不应太长以避免 ANR)。
接收器很可能是应用程序运行的唯一组件
作为奖励,我最近了解到一些用 FLAG_RECEIVER_REGISTERED_ONLY 标记的 Intent 是 only delivered动态注册的接收者 - 是否有任何地方列出这些 Intent ?

最佳答案

I am not quite certain what the behavior of a BroadcastReceiver, registered in the manifest and enabled via PackageManager, is when the phone is asleep.

大多数广播不会唤醒设备。

which broadcasts are guaranteed to wake up a receiver when the phone has fallen asleep (as in left alone for quite some time)

我怀疑您能否在某处找到明确的列表。我记得唯一符合您描述的广播是 SMS_RECEIVED 和任何通过 AlarmManager 触发的广播和广播 PendingIntent

and keep the phone awake as long as onReceive() runs

SMS_RECEIVED 可能有这种行为,但我不确定。 AlarmManager 场景确实如此。

(which of course should not be too long to avoid ANR).

它需要比这短得多,因为如果您碰巧有前台 Activity ,它会卡住您的 UI。任何超过几毫秒的时间都需要委托(delegate)给具有后台线程的服务,例如我的 WakefulIntentService

As a bonus, I recently learned that some intents, flagged with FLAG_RECEIVER_REGISTERED_ONLY, are only delivered to dynamically registered Receivers - is there any place listing those intents ?

不,在源代码之外。想到的包括:ACTION_SCREEN_ONACTION_SCREEN_OFFACTION_BATTERY_CHANGED

关于android - 手机休眠时的 BroadcastReceiver 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16254420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com