7

can someone please let me know where Im going wrong. From what I can see on instructions....theres no amendments required to Android specific files if you are only using local notifications and also using autolinking....except for adding googlePlayServicesVersion = "<Your play services version>" // default: "+" to android/build.gradle....and <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> plus <uses-permission android:name="android.permission.VIBRATE" /> to AndroidManifest.xml

Below is my main source code

PushNotification.configure({
  // (optional) Called when Token is generated (iOS and Android)
  onRegister: function(token) {
    console.log('onRegister token:', token);
  },

  // (required) Called when a remote is received or opened, or local notification is opened
  onNotification: function(notification) {
    console.log('onNotification:', notification);
    notification.finish(PushNotificationIOS.FetchResult.NoData);
  },

  // Should the initial notification be popped automatically
  popInitialNotification: true,
  requestPermissions: true,
});

  userNowInactive = () => {
          this.showNotification();
 }

  showNotification = () => {
    PushNotification.localNotification({
      //ios and android properties
      title: 'Face2Face: Beacon Timer Expired',
      message: 'Perhaps set your beacon timer for another hour?',
      playSound: true,
      soundName: 'sound.mp3',
      //android only properties
      channelId: 'your-channel-id',
      autoCancel: true,
      // largeIcon: 'ic_launcher',
      // smallIcon: 'ic_launcher',
      bigText: 'Face2Face: Beacon Timer Expired',
      subText: 'Perhaps set your beacon timer for another hour?',
      vibrate: true,
      vibration: 300,
      priority: 'high',
      //ios only properties...is there any?
    });
  };
james murphy
  • 1,505
  • 5
  • 31
  • 57

1 Answers1

22

Did you create a channel? It seems you need to create one to get it to work.

https://github.com/zo0r/react-native-push-notification#channel-management-android

To use channels, create them at startup and pass the matching channelId through to PushNotification.localNotification or PushNotification.localNotificationSchedule.

PushNotification.createChannel(
    {
      channelId: "channel-id", // (required)
      channelName: "My channel", // (required)
      channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
      playSound: false, // (optional) default: true
      soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
      importance: 4, // (optional) default: 4. Int value of the Android notification importance
      vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
    },
    (created) => console.log(`createChannel returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
  );
Ade Crown
  • 1,120
  • 14
  • 16
  • Yes thank you this is correct answer. Channels must be a recent mandatory part of libraby as it was working prior to "npm install". I guess lesson is to check every library functionality carefully every time you upgrade library – james murphy Feb 24 '21 at 04:44
  • for me it is showing createChannel returned false – Shubham Kumar Nov 24 '21 at 11:41
  • 1
    @ShubhamKumar if it returns false that means the channel already existed. Also you don't have to call the last line, it's optional. – Ade Crown Nov 26 '21 at 11:14