且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

XAMARIN.FORMS:如果应用程序在 Android 后台运行,FCM 推送通知将不会振动

更新时间:2022-01-02 23:00:13

在 Oreo(+) 上,您必须通过 EnableVibration(true)NotificationChannel 上启用振动>.

On Oreo(+), you have to enable the vibration on the NotificationChannel via EnableVibration(true).

NotificationChannel channel;
channel = notificationManager.GetNotificationChannel(myUrgentChannel);
if (channel == null)
{
    channel = new NotificationChannel(myUrgentChannel, channelName, NotificationImportance.High);
    channel.EnableVibration(true);
    channel.EnableLights(true);
    channel.SetSound(
        RingtoneManager.GetDefaultUri(RingtoneType.Notification),
        new AudioAttributes.Builder().SetUsage(AudioUsageKind.Notification).Build()
    );
    channel.LockscreenVisibility = NotificationVisibility.Public;
    notificationManager.CreateNotificationChannel(channel);
}
channel.Dispose();