Giter Club home page Giter Club logo

Comments (7)

vincent-unity avatar vincent-unity commented on June 24, 2024 1

Thanks for reporting this.
I don't know why it's -1000 at the beginning, but you're right according to the android doc. Will have a check.

from com.unity.mobile.notifications.

vincent-unity avatar vincent-unity commented on June 24, 2024 1

Thanks! So it's a different story on device below Android 8, as there is no notification channel support.

from com.unity.mobile.notifications.

vincent-unity avatar vincent-unity commented on June 24, 2024

I looked into this issue today, would like to share what I found.

  1. Android document said VISIBILITY_PUBLIC is 1, https://developer.android.com/reference/android/app/Notification#VISIBILITY_PUBLIC. But I found if you set a channel to Show all notifications ... in System Settings, NotificationChannel.getLockscreenVisibility() will return -1000. Also if you don't set the LockScreenVisiblity when creating the notification channel, it will be -1000 by default.

  2. NotificationChannel.setLockscreenVisibility() won't work from code anyway. check the comment here by searchingOnly modifiable by the system and notification ranker.. This means the value can only be changed from System settings or by Android Notification Ranking Service. I did a quick experiment by doing below

    protected void createNotificationChannel(NotificationManager notificationManager)
    {
        NotificationChannel channel = new NotificationChannel(k_ChannelId, "Test Default", NotificationManager.IMPORTANCE_DEFAULT);

        Log.w("Create Channel", String.format("Default lockscreen: %d", channel.getLockscreenVisibility()));
        channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
        Log.w("Create Channel", String.format("Set lockscreen %d", channel.getLockscreenVisibility()));

        notificationManager.createNotificationChannel(channel);
    }

    protected void printNotificationChannel(NotificationManager notificationManager)
    {
        NotificationChannel channel = notificationManager.getNotificationChannel(k_ChannelId);
        Log.w("Print Channel", String.format("Get lockscreen %d", channel.getLockscreenVisibility()));
    }

I got the below results

2020-04-13 16:52:38.320 17408-17408/com.example.testvibration W/Create Channel: Default lockscreen: -1000
2020-04-13 16:52:38.321 17408-17408/com.example.testvibration W/Create Channel: Set lockscreen 0
2020-04-13 16:52:49.375 17408-17408/com.example.testvibration W/Print Channel: Get lockscreen -1000

Then I went to System Settings to change the lockscreen visibility to Hide senstitive ....(private), I got

2020-04-13 16:57:36.180 17408-17408/com.example.testvibration W/Print Channel: Get lockscreen 0

At last I switched back to Show all notification contents, I got,

2020-04-13 16:59:36.190 15045-15045/com.example.testvibration W/Print Channel: Get lockscreen -1000

So my conclusions are

  • you can't really set the lockscreen visibility from code...
  • -1000 stands for public

And my question is do we really provide LockScreenVisibility setter for NotificationChannel...

from com.unity.mobile.notifications.

Maicolo avatar Maicolo commented on June 24, 2024

Interesting, thanks for the heads up Vincent!

If I use AndroidNotificationCenter.RegisterNotificationChannel passing a channel where 'LockScreenVisibility' has been seto to 'LockScreenVisibility.Secret', the channel seems to work as intended. I can't see any notification fired on that channel in the lock screen.

from com.unity.mobile.notifications.

vincent-unity avatar vincent-unity commented on June 24, 2024

So weird... We have tests on NotificationChannel which all the returned value of NotificationChannel.LockscreenVisibility are Public, no matter which value you set on creation. I'm personally testing on Google Pixel 2 with Android 8.

So could you please check what NotificationChannel.LockscreenVisiblity returns for a registered channel? Please use AndroidNotificationCenter.GetNotificationChannel() to retreive the registered channel. I'm expecting it returns Private (which should be Public as I'm going to fix).

Btw, you have to uninstall/reinstall the app to test as you can't change an registered notfication channel from code per Android!

from com.unity.mobile.notifications.

Maicolo avatar Maicolo commented on June 24, 2024

Sorry for the late answer Vincent,
so I have performed the test you asked me. To be clear I am using the version 1.0.3 of the mobile notification package and I am testing on a very old KitKat Android phone.

After registering three different channels with the three different visibility values this is the output:

I/Unity: The visibility for the channel 'game_normal_channel' is: Public
I/Unity: The visibility for the channel 'game_private_channel' is: Private
I/Unity: The visibility for the channel 'game_silent_channel' is: Secret

I confirm that the 'Public' and the 'Secret' channel work just fine while the 'Private' one bahaves like the 'Public' one.

from com.unity.mobile.notifications.

vincent-unity avatar vincent-unity commented on June 24, 2024

Fixed in 1.2.0-preview.

from com.unity.mobile.notifications.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.