question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Sound does not work depending model device or the version of Android

See original GitHub issue

Bug

I have the following problem: On a given device, the customized sound and vibrate works normally, and on another device only the standard sound works and no vibrate never.

Environment info

Device custom sound and vibrate ok: Vernee Mars pro Android 7.0 Device custom sound dont play (play default) and vibrate not work: Xiaomi Mi A2 Lite Android 10. Using PushNotification.checkPermissions on 2 devices I get: { alert: true }, nothing appears about badge or sound.

System: OS: Windows 10 10.0.18362 CPU: (4) x64 Intel® Core™ i5-4570 CPU @ 3.20GHz Memory: 5.39 GB / 15.88 GB Binaries: Node: 12.18.3 - C:\Program Files\nodejs\node.EXE Yarn: 1.13.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.14.6 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: API Levels: 23, 27, 28, 29 Build Tools: 23.0.1, 27.0.3, 28.0.3, 29.0.2, 30.0.2 System Images: android-27 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom Android NDK: Not Found Windows SDK: Not Found IDEs: Android Studio: Version 4.0.0.0 AI-193.6911.18.40.6626763 Visual Studio: Not Found Languages: Java: 1.8.0_201 Python: 2.7.15 npmPackages: @react-native-community/cli: Not Found react: 16.13.1 => 16.13.1 react-native: 0.63.3 => 0.63.3 react-native-windows: Not Found npmGlobalPackages: react-native: Not Found

Library version: x.x.x react-native-push-notification": “^6.1.1”,

Reproducible sample code

PushNotification.channelExists('channel-push-rotina', (exists) => {
      if (!exists) {
        PushNotification.createChannel({
          channelId: 'channel-1489', // (required)
          channelName: 'PushChanel', // (required)
          vibrate: true,
          // soundName: 'alertsound2', // (optional) See `soundName` parameter of `localNotification` function
        });
      }
    });
  function sendNotification() {
    PushNotification.localNotification({
      title: '14:00 - TITLE HERE',
      channelId: 'channel-push-rotina',
      message: 'You pushbutton ou push the nn button!',
      smallIcon: 'ic_notification',
      largeIcon: 'ic_launcher',
      soundName: 'alertsound2',
      playSound: true,
      vibrate: true,
      vibration: 1000,
      autoCancel: false,
      actions: ['close'],
    });
  }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8

github_iconTop GitHub Comments

2reactions
fieldesignercommented, Oct 21, 2020

sorry for my english, i speak english as well as i’m a programmer 😃

Sorry the code I sent didn’t really match what I had, I probably had already tried so much that when posting my example I was wrong to post with the commented line.

So … you’re right, after switching libs when trying to build, I got other errors that the original lib didn’t occur, so I went back, and decided to do more tests, and realized that for my project I really needed to create 2 channels, 1 with the default sound and one with the custom sound, and there it worked beautifully.

Sorry for taking your time. Below the code that worked for me.

PushNotification.channelExists('rn-push-notification-channel', (exists) => {
      if (!exists) {
        PushNotification.createChannel({
          channelId: 'rn-push-notification-channel', // (required)
          channelName: 'PushChanelDefault', // (required)
          channelDescription: 'Canal de notificações padrão', // (optional) default: undefined.
          vibrate: true,
        });
      }
    });
    PushNotification.channelExists(
      'rn-push-notification-channel-alert',
      (exists) => {
        if (!exists) {
          PushNotification.createChannel({
            channelId: 'rn-push-notification-channel-alert', // (required)
            channelName: 'PushChanelAlert', // (required)
            channelDescription: 'Canal de notificações Alarme', // (optional) default: undefined.
            vibrate: true,
            soundName: 'my_sound.mp3', // (optional) See `soundName` parameter of `localNotification` function
          });
        }
      },
    );
function sendNotification() {
    PushNotification.localNotification({
      title: '14:00 - TÍTULO AQUI',
      channelId: 'rn-push-notification-channel-alert',
      message: 'You pushbutton ou push the nn button!',
      smallIcon: 'ic_notification',
      largeIcon: 'ic_launcher',
      soundName: 'my_sound.mp3',
      playSound: true,
      vibrate: true,
      vibration: 1000,
      autoCancel: false,
      actions: ['Fechar'],
    });
  }
1reaction
Dallas62commented, Oct 21, 2020

Nice to see it works !

This is probably because the sound was not set the first time the code run, then the channel wasn’t updated.

It would take me too much time for now, but there is some improvement needed in the documentation. Too much important information… 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

A reason why custom notification sound might not work on ...
When we use custom sound for a notification channel, we might observe that system shows notifications without sound. Playing custom sound ...
Read more >
notification custom sound not working with some devices
Whenever you do some changes in notification channel config, either re-install app or clear data. Make sure you are adding both Channel.setSound ...
Read more >
How to Change Your Android Notification Sound
Tap Default notification sound. ; Tap Notification sound. ; Open Settings > Apps (you may have to select Your apps depending on your...
Read more >
How to Fix Android Messages Having No Notification Sound
Tap the Sound option and select one of your ringtones / notification ; this will be the sound that plays when you get...
Read more >
Create and Manage Notification Channels - Android Developers
Starting in Android 8.0 (API level 26), all notifications must be assigned to a channel. For each channel, you can set the visual...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found