【问题标题】:RECEIVE_BOOT_COMPLETED not received for my app on API Level 30, but received on API Level 21我的应用在 API 级别 30 上未收到 RECEIVE_BOOT_COMPLETED,但在 API 级别 21 上收到
【发布时间】:2020-12-07 02:21:48
【问题描述】:

我通过在manifest 中输入并实现MyBootReceiver.onReceive(..) 来实现RECEIVE_BOOT_COMPLETED。

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
....
<receiver
            android:name=".MyBootReceiver"
            android:enabled="true"
            android:exported="false" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
            </intent-filter>
        </receiver>

在模拟器 (Pixel 2 API 21) 上运行时效果很好。但是,当它在 API 级别 30 或物理设备 OnePlus 6 (Oxygen 10.3.7) 上运行时,不会收到 BOOT 通知。

但是,当手机重新启动时,Whatsapp、Sms 等其他应用程序能够从服务器接收消息,可能使用一些通知事件。这怎么可能?

我错过了什么吗?

【问题讨论】:

    标签: android


    【解决方案1】:

    一加和小米在 Android 之上定制了他们的操作系统。所以他们已经覆盖了这个功能。参考Broadcast Receiver Not Working After Device Reboot in Android

    在较新的 Android 版本上,您需要运行 adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -p com.mypackage.name。在不限制广播到您的应用的情况下,您的设备实际上会重新启动

    regd 你的问题,

    但是,当手机重新启动时,其他应用程序,如 Whatsapp、Sms 等能够从服务器接收消息,可能使用一些 通知事件。这怎么可能?

    也可以通过访问电话网络状态来实现

    【讨论】:

    • 当我运行你给出的 abd 命令时,我得到以下错误:adb -s emulator-5554 shell am broadcast -a android.intent.action.BOOT_COMPLETED -p com.xxxx Broadcasting: Intent { act=android.intent.action.BOOT_COMPLETED flg=0x400000 pkg=com.filesuploader } Exception occurred while executing 'broadcast': java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.BOOT_COMPLETED from pid=4995, uid=2000
    • 自设备重启后应用未运行时,访问手机网络状态有何帮助?
    • 我可以知道您在 MyBootReceiver 中正在做什么。如果您正在运行服务,则后台执行限制适用于从奥利奥开始developer.android.com/about/versions/oreo/background
    • 我现在认为,Whatsapp 等使用 JobScheduler / WorkerProcess
    • 是的,我建议您在广播接收器中添加日志,以检查您是否真的接收到广播。然后尝试使用前台服务/ workmanger 服务于目的
    猜你喜欢
    • 2021-01-03
    • 1970-01-01
    • 2021-07-19
    • 2021-06-01
    • 1970-01-01
    • 2014-01-01
    • 2020-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多