简体   繁体   中英

how to enable floating notification and lock screen notification in xamarin android(Java or Kotlin is okay)

I make simple notification android app using xamarin, i want floating notification and lock screen notification在此处输入图像描述

l add users permission in manifest, also i read all reference document about notification channel however i don't know how to enable floating notification and lock screen notification in code

outlook, gmail etc. some app enable all notification when it installed

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

above screenshot is my app

i want enable all notification when installed my app necessarily Even if it is not in xamarin, a solution using kotlin or java is fine!

For floating notification , you should change Notification priority or NotificationChannel importance.

Android 5.0 - Android 7.1

Set notification priority to NotificationPriority.High or NotificationPriority.Max .

builder.SetPriority((int)NotificationPriority.High)

Set ringtone and vibrations. You can use SetDefaults.

 // Turn on sound if the sound switch is on:                 
                notification.Defaults |= NotificationDefaults.Sound;

            // Turn on vibrate if the sound switch is on:                 
                notification.Defaults |= NotificationDefaults.Vibrate;

Android 8.0 and higher

Set notification channel priority to NotificationImportance.High or NotificationImportance.Max.

 var channel = new NotificationChannel(CHANNEL_ID1, name, NotificationImportance.Max)
        {
            Description = description
        };

For lock notifications , you could set the Visibility.

Beginning with Android 5.0, the visibility setting is available to control how much notification content appears on the secure lock screen.

  • NotificationVisibility.Public – The full content of the notification is displayed on the secure lock screen.

  • NotificationVisibility.Private – Only essential information is displayed on the secure lock screen (such as the notification icon and the name of the app that posted it), but the rest of the notification's details are hidden. All notifications default to NotificationVisibility.Private.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM