leolin310148 / ShortcutBadger

An Android library supports badge notification like iOS in Samsung, LG, Sony and HTC launchers.
Other
7.35k stars 1.34k forks source link

Update Badge Number in Background Notification on Android #379

Open ash737 opened 1 year ago

ash737 commented 1 year ago

I'm using ShortcutBadger latest version with cordova-plugin-fcm-with-dependecy-updated Notification badge update ok in ios by set badge number in payload but, in android cannot set badge in payload

How to get this work using ShortcutBadger and FCM?

aravindforums1 commented 1 year ago

I'm using ShortcutBadger latest version with cordova-plugin-fcm-with-dependecy-updated Notification badge update ok in ios by set badge number in payload but, in android cannot set badge in payload

How to get this work using ShortcutBadger and FCM?

Hi did u get badge count in app icon for ios and android ? or ios only ? pls reply i stuck in show badge count in app icon for android cant find it. Can you share code how to set badge count and update ?

ash737 commented 1 year ago

Hi, In iOS, you have to store notification info into database then, calculate badge number, increase one, and set it in payload as badge:

function send_notification ($notiunreadNO, $token, $message, $title)
{
    $notiunreadNO = $notiunreadNO + 1;

    $fields = array(
        'to' => $token,
        'notification' => array('title' => $title, 'body' => $message, 'click_action' => 'FCM_PLUGIN_ACTIVITY', 'badge' => $notiunreadNO),
        'data' => array('title' => $title, 'body' => $message),
        'sound' => 'default'
    );
}

For android, I still looking for a solution.

I'm using ShortcutBadger latest version with cordova-plugin-fcm-with-dependecy-updated Notification badge update ok in ios by set badge number in payload but, in android cannot set badge in payload How to get this work using ShortcutBadger and FCM?

Hi did u get badge count in app icon for ios and android ? or ios only ? pls reply i stuck in show badge count in app icon for android cant find it. Can you share code how to set badge count and update ?

aravindforums1 commented 1 year ago

Hi, In iOS, you have to store notification info into database then, calculate badge number, increase one, and set it in payload as badge:

function send_notification ($notiunreadNO, $token, $message, $title)
{
    $notiunreadNO = $notiunreadNO + 1;

  $fields = array(
      'to' => $token,
      'notification' => array('title' => $title, 'body' => $message, 'click_action' => 'FCM_PLUGIN_ACTIVITY', 'badge' => $notiunreadNO),
      'data' => array('title' => $title, 'body' => $message),
      'sound' => 'default'
  );
}

For android, I still looking for a solution.

I'm using ShortcutBadger latest version with cordova-plugin-fcm-with-dependecy-updated Notification badge update ok in ios by set badge number in payload but, in android cannot set badge in payload How to get this work using ShortcutBadger and FCM?

Hi did u get badge count in app icon for ios and android ? or ios only ? pls reply i stuck in show badge count in app icon for android cant find it. Can you share code how to set badge count and update ?

Ok , Thanks for your reply, i tried with "cordova-plugin-firebase-messaging 7.0.4 "FirebaseMessagingPlugin" , but still cant in Android, If found solution, please share it.

aravindforums1 commented 1 year ago

Hi, In iOS, you have to store notification info into database then, calculate badge number, increase one, and set it in payload as badge:

function send_notification ($notiunreadNO, $token, $message, $title)
{
    $notiunreadNO = $notiunreadNO + 1;

  $fields = array(
      'to' => $token,
      'notification' => array('title' => $title, 'body' => $message, 'click_action' => 'FCM_PLUGIN_ACTIVITY', 'badge' => $notiunreadNO),
      'data' => array('title' => $title, 'body' => $message),
      'sound' => 'default'
  );
}

For android, I still looking for a solution.

I'm using ShortcutBadger latest version with cordova-plugin-fcm-with-dependecy-updated Notification badge update ok in ios by set badge number in payload but, in android cannot set badge in payload How to get this work using ShortcutBadger and FCM?

Hi did u get badge count in app icon for ios and android ? or ios only ? pls reply i stuck in show badge count in app icon for android cant find it. Can you share code how to set badge count and update ?

Could you share code which set badge in device ? i mean how to set badge count in mobile device , above is payload to send notification, but i need in mobile device how to set count ? Point 1 and 2 in which file need to add and point 3 ondeviceready function need to add ?