仅当应用程序在 android pie 中关闭时,广播接收器才不起作用

Ade*_*har 8 android background broadcastreceiver

我每次都使用Broadcast Receiver触发incoming messages。它在Android O任一应用程序中的工作正常是否关闭。但Android P它仅在应用程序处于活动状态和应用程序关闭时才有效。无论应用程序是关闭还是不在Android P. 我遵循了这个链接和许多其他链接,但问题仍然存在。

清单中的接收者注册

<receiver
            android:name=".Broadcast.SmsListener"
            android:enabled="true"
            android:exported="true"
            android:permission="android.permission.BROADCAST_SMS">
            <intent-filter android:priority="999">
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
Run Code Online (Sandbox Code Playgroud)

广播接收器类

    public class SmsListener extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("Resulted12", "Into onReceive()");
        context.startService(new Intent(context, BackgroundService.class));
    }
}
Run Code Online (Sandbox Code Playgroud)

还有什么我错过的吗?

Ade*_*har 8

花了几天后,我发现了真正的问题。

我的代码在Android OAndroid P上的前台后台运行良好,但是当我从最近的应用程序列表中清除该应用程序时,它在某些设备上停止工作,因为

制造商默认添加了任务管理器功能,强制停止应用程序进行内存/电池管理。但很少有应用程序像 Whatsapp、Facebook 一样有效。这可能是因为他们会将最著名的应用程序列入白名单。

欲了解更多信息,请点击以下链接

清除最近的应用程序擦除应用程序内存,我的接收器停止工作