设备重启(或类似状态)时不显示本地通知 Android

Local notifications not showing up when device is rebooted (or similar state) Android

我有点新,所以我有一个简单的问题,我创建了一个 Xamarin.Android 应用程序,我已经使用带有警报管理器、广播接收器等的本地通知来安排它们,我的问题有一个问题是,当设备重新启动或完全关闭状态并再次打开时,我的预定通知没有显示。我的问题是:

Android 里面有问题吗? 除此以外 我该如何解决?

希望得到帮助,谢谢

默认情况下,设备关闭时所有警报都会被取消。

https://developer.android.com/training/scheduling/alarms

By default, all alarms are canceled when a device shuts down. To prevent this from happening, you can design your application to automatically restart a repeating alarm if the user reboots the device. This ensures that the AlarmManager will continue doing its task without the user needing to manually restart the alarm.

您需要监控 BOOT_COMPLETE 并重新设置闹钟。

https://developer.android.com/reference/android/Manifest.permission.html#RECEIVE_BOOT_COMPLETED

清单:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>


<receiver android:name=".SampleBootReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"></action>
    </intent-filter>
</receiver>

接收者:

class SampleBootReceiver : BroadcastReceiver() {

    override fun onReceive(context: Context, intent: Intent) {
        if (intent.action == "android.intent.action.BOOT_COMPLETED") {
            // Re-set the alarm here.
        }
    }
}