1

I make simple notification android app using xamarin, i want floating notification and lock screen notification enter image description here

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

enter image description here

enter image description here

enter image description here

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!

Sunday
  • 109
  • 1
  • 9

1 Answers1

2

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.

Wendy Zang - MSFT
  • 10,509
  • 1
  • 7
  • 17
  • oh sorry my comment is to late, i changed notification importance and notificationvisiblity but i can get floating notification and lockscreen notification. i think change app notification settings. Is there any way i can change the notification settings through programming? – Sunday Dec 27 '20 at 14:59
  • Could it be the problem that my test device is a Xiaomi? – Sunday Dec 27 '20 at 15:23
  • Do you mean you could get floating notification and lockscreen notification? Which notification settings you want to change through programming? – Wendy Zang - MSFT Dec 28 '20 at 09:28
  • Sorry, I made a typo. I did all the things required by the various articles. they said i should change lockscreen visibility, Notification Importance. but i can't get floating notification and lockscreen notification. I guess. In the notificationTest app picture above, floating notifications and lockscreen notifications are turned off. then if i turn on it, maybe i can get notifications. if you know how to turn on it, please tell me – Sunday Dec 29 '20 at 00:09
  • The seetings for the app would not affect. Have you tried my code? If the code still does work, could you provide the code you used for the notification? – Wendy Zang - MSFT Dec 31 '20 at 08:55
  • 3
    Further investigation revealed that on xiaomi devices, apps that are not registered in the white list must be set by the user. – Sunday Dec 31 '20 at 14:55
  • 1
    Your answer is correct. problem was just the Xiaomi device – Sunday Dec 31 '20 at 14:55
  • Hi @Sunday, could you give me a link on where I can read about your further investigation on white listed app on xiaomi device? Thank you – Komang Sidhi Artha Apr 12 '21 at 01:26
  • https://dontkillmyapp.com/xiaomi https://stackoverflow.com/questions/51257052/how-to-whitelist-my-android-app-to-china-manufacturer-like-xiaomi-oppo-etc https://c.mi.com/thread-1545043-1-0.html I saw above document – Sunday Apr 12 '21 at 06:11