Huawei EMUI 8 Oreo - Notification Channel - Tone - android

Some users are reporting on Huawei EMUI 8.0 Oreo that the Notification Channel does not have the option to change tone "Sound" / "Notification Tone" from the app!
As of the official docs the developer can't change the settings anymore.
So how can I add an option for Huawei phones to change the "Notification Tone" again?
And does anyone know why the hell Huawei removed this feature?
I don't find official docs from Huawei how we can now let the user change the notification tone.
Offical docs I am referring:
https://developer.android.com/reference/android/app/NotificationChannel.html
https://developer.android.com/reference/android/app/NotificationChannel.html#setSound(android.net.Uri, android.media.AudioAttributes)

We ran into the same issue recently.
It is not a nice solution, but WhatsApp is doing the same.
Basically we show a ringtone selection inside our app and then delete and recreate the notification channel with a new channel id and the selected ringtone uri. You can copy most settings made to the channel to the new one except 'do not disturb'.
Like I said it is not a nice solution and I don't know what will happen if the channel is recreated a lot. But hopefully the ringtone is not changed too often.
Note: The notification settings screen displays the number of deleted channels, as a spam prevention mechanism.

Faced with same issue on chinese devices. Firstly, i have same solution like describe #Devenias. How it works in system: when you're defining a new channel, NotificationService save this channel in xml, after you changed it, it still contains in this xml. So on a new change of channel, NotificationService will check if it have a channel with a same name, and just retrieve it. So i make new channel with a new settings all the time, when user change vibration or ringtone in app. Also it works like a cache, just make unique channel name for pair<ringtone, vibration>. This solution is pretty hacky, since it works good on Honor's, Huawei's, Samsung's devices and Xiaomi Mi A1, but it have been crashing NotificationService with NullPointer in SystemUI on Xiaomi Mi Mix 2 (device make soft reboot, if SystemUI service crashed), so don't use this solution.
So nowadays a safe workaroud is to play sound and vibration manually.

Related

Ringtone not playing on certain Samsung devices with Android 11

I'm working on a VoIP app and when a call comes in, the ringtone is not audible on at least a Samsung A20e and a Samsung A71 device running on Android 11. Unfortunately, this info came from a few users who say they experience the issue and the issue doesn't arise on all the phones I have access to, so I'm not able to look in the logs myself.
To get the ringtone URI, the following code is used:
val uri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE)
Then that URI is used on the notification channel:
val attributes = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.build()
notificationChannel.setSound(uri, attributes)
And the URI is used once again in the method setSound of the NotificationCompat.Builder to generate the actual notification.
I tried to reproduce the issue on an emulator and changed the values in setUsage and setContentType a lot, but nothing seemed to have impact. I also reinstalled the app on every change, to make sure a new notification channel would be created.
Then I read somewhere on the internet that ringtones never work on an emulator. However, I do have an emulator on which the ringtone is actually audible, so I'm not so sure that's true, at least not for every configuration.
Lastly I should add that the ringtone also wasn't silent on my original emulator when I added the following line:
RingtoneManager.getRingtone(context, uri).play()
However, I'm not actually able to use that piece of code, since I need to attach the ringtone to a notification (channel).
Does anyone have experience with a same type of issue? Is there a problem with the settings of my notification or the notification channel? Is this just a Samsung issue? I hope someone can help me out.
I'll answer my own question. Turns out the client didn't describe the issue thorough enough and it turned out to be an easily solvable issue when he provided us with more information. The ringtone would be audible when the notification volume of the phone was on and the ringtone volume of the phone was off. However, when the notification volume was off and the ringtone volume was on, the ringtone wouldn't be audible. So the two of those got switched around, which got fixed by replacing AudioAttributes.USAGE_NOTIFICATION with AudioAttributes.USAGE_NOTIFICATION_RINGTONE.

Notification limit dropped to 24 per app in Android 11 notification drawer

Is there any limit on the number of notifications the android app can display? I am facing an issue after 24 notifications android notification does not appear.
There is no documentation which states this clearly.
This issue I have observed in Android 11. Looks like this is applicable to android 10 (https://support.google.com/pixelphone/thread/23619509?hl=en). I don't have android 10. So, I have not tested.
Please help me to get a documentation reference for this limit or this behavior can be changed using the settings of the device.
Yes, there is a limit of notifications that can be posted per app. The interesting thing was the number is not fixed and can be controlled by the Device Manufacturer. From my observation, a Google Pixel 3A phone had limited to 25 notifications were as an OnePlus 6T and a Samsung device had limited the notifications to 50.
If we carefully observe the NotificationManagerService.java source code, we can see a variable MAX_PACKAGE_COUNT declared to be 50.
And inside the code, it checks if the count is greater than the MAX_PACKAGE_NOTIFICATIONS, it has a message saying that “Package has. already posted max toasts. Not showing more!”
This is the reason we get limited by the number of notifications that are posted per app.
The number of notifications for a particular application has been set to 50 which is a default value set in notification manager. But more on that, the device manufacturer can also set this limit on their own.
Problem : Now the problem is that we can not change this number as it is not accessible to us or even visible.
Solution : If we want that our application delivers notifications continuously, we need to change a little bit of code in our application.
We have to clear the previous notifications which are not needed.
For that we can set Notification.builder.
NotificationCompat.Builder builder = new NotificationCompat.Builder(...);
builder.setContentTitle(...);
builder.setContentText(...);
builder.setTimeoutAfter(5000);
builder.setTimeoutAfter(5000);
The above line will auto-clear notifications after 5 seconds of notification arrival.
So newer notifications can be pushed by your application.
References : 1. Notification builder
2. builder.setTimeOutAfter();

how to play sound in service worker or even vibrate in chrome?

I am using service workers. I need it for push notifications. What I want to achieve is that when I recieve notification, it should play a sound or vibrate at least.
self.registration.showNotification(title, {
body: body,
icon: './assets/images/icons/icon_144x144.png',
vibrate: [200, 100, 200, 100, 200, 100, 200],
});
I am having this piece of code upon receiving a notification.
Problem 1: No vibration happens at all. Then I went ahead of a little bit debugging.
https://googlechrome.github.io/samples/notifications/vibrate.html This DOESN'T vibrate my phone.
https://googlechrome.github.io/samples/vibration/index.html This DOES vibrate my phone.
Why doesn't it vibrate from the first link? I am testing all this on android chrome.
Problem 2: Looks like on firefox, it does have a default sound. Why doesn't google have the same sound? It just goes silent. No way I can play sound ? at least I want to vibrate it...
As shown here, the vibrate property of showNotification() is no longer supported on Android devices from Android O onward, regardless of the Chrome version, which is likely why the first link doesn't work for you.
However, you can use the vibrate() method (which is what the second link is doing), which is supported on Chrome versions after version 32. However note that after Chrome 60, this method will only work in response to a user gesture. (see https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate) for more details.
Adding some more history here:
According to the Chromium devs:
Unfortunately we've had to deprecate this starting Android O a few years ago - introduction of notification channels means that attention drawers (vibration, sound and all) are now per channel rather than per notification, which Chrome doesn't enable developers to configure.
Addressing that has zero interest from other vendors unfortunately.

What is the "Uncategorized" Android Notification Channel and when does it appear?

While transitioning an application to Android O, I have noticed a strange thing. Sometimes my foreground service notification goes into a channel that I have not made, called "Uncategorized". I have no idea how or when this happens.
The channels are always created before the notifications start being posted, and the ID of the channel is correct. I have tried putting in a random String as the channel ID to see if I could reproduce the issue, but the notification just doesn't get posted in that case. So it seems to be some weird case when the channel was already created before.
This is the channel's page:
And this is the channel appearing in the list of all channels of the app (note, I have removed the icon for privacy reasons).
Does anyone have any experience with this and could they explain when this can happen? Unfortunately, I found no documentation regarding this, and heard nothing about it in the Google I/O talks.
I think this is what happens if a part of your app does not support notification channel it seems.
Specifically in our case, if a SDK of ours is notification channel capable, but an app targets 25 and uses legacy features. We will always have legacy app notification go to that Uncategorized channel.
I can imagine there are other cases where the OS decides you need this channel because the OS thinks not everything is migrated properly. Do you have a targetSDK of 26 for the entire app with forced 26.0.1 support libs?
When I changed my target SDK to API Level 27 in my app I longer saw the Uncategorized category.

Android 5 turn off Interruptions filtration

Just tested my app on new Android 5.0 and found that it have some bug in switching ringer mode via Audio Manager. After set RINGER_MODE_SILENT it comes to "Allow only priority interruptions" mode and it's ok, it's how described in what's new document. But after set RINGER_MODE_NORMAL phone doesn't come back to "Always interrupt" and this is not expected behavior. User can miss the call because of it.
Does someone find solution/work around this problem? How can I turn off this filtration mode?
Update
Found this code in Android src. This settings is Global.ZEN_MODE. And code that should change it on set NORMAL_MODE looks like correct, but it doesn't work in Emulator and Nexus ROM. Had try to set via Settings.Global.putInt, but got error about permissions. Have no idea how to fix it =(
Made bug report: https://code.google.com/p/android/issues/detail?id=78158&thanks=78158&ts=1414182304
And in preview tracker https://code.google.com/p/android-developer-preview/issues/detail?id=1780&thanks=1780&ts=1414218141
Just found some work around. We can use NotificationListenerService.requestInterruptionFilter to change filtration mode. It works, but you have to add your service in "Notification access" list (it's in Sound & notification settings), otherwise you will have no permissions.

Categories

Resources