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

Excuse me,I use the ShortcutBadger.applyNotification(getApplicationContext(), notification, badgeCount) method in my xiaomi device,it still donot work .My Device is xiaomi 4X。 #305

Open hexiangbing opened 6 years ago

vuhung3990 commented 6 years ago
private fun showBadge(count: Int) {
    if (isXiaomiDevice(Build.MANUFACTURER)) {
      val notificationManager = getSystemService(
          Context.NOTIFICATION_SERVICE) as NotificationManager
      createChannel(notificationManager, NOTIFICATION_CHANNEL)
      val notification = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL)
          .setSmallIcon(R.mipmap.ic_launcher_round)
          .build()

      ShortcutBadger.applyNotification(applicationContext, notification, count)
      notificationManager.notify(22, notification)
    } else {
      ShortcutBadger.applyCount(applicationContext, count)
    }
  }

  private fun createChannel(notificationManager: NotificationManager,
      NOTIFICATION_CHANNEL: String) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
      val channel = NotificationChannel(NOTIFICATION_CHANNEL, "ShortcutBadger Sample",
          NotificationManager.IMPORTANCE_DEFAULT)
      notificationManager.createNotificationChannel(channel)
    }
  }

  private fun isXiaomiDevice(manufacturer: String): Boolean {
    return manufacturer.equals("xiaomi", true)
  }

then call showBadge(49)