OneSignal-Android-SDK icon indicating copy to clipboard operation
OneSignal-Android-SDK copied to clipboard

[Feedback]: The OneSignal SDK should offer a way to check whether a Notification channel created through OneSignal is enabled.

Open raffaelgyr opened this issue 2 years ago • 4 comments

What's on your mind?

In the OneSignal dashboard we can create Android Notification Channels, and the OneSignal SDK then creates these channels on the users device. After a notification channel has been created, the user can disable the channel to stop receiving certain notifications.
The OneSignal SDK seemingly doesn't provide a way for the app to check, whether a notification channel that was created through OneSignal is currently enabled or disabled and I am requesting that such a function should be added.

I often receive complaints from users that they don't receive notifications and disabled notification channels are one reason why they might not be receiving the notifications. If I was able to read out this value, I could let the user know what the problem is directly in the app.

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

raffaelgyr avatar May 23 '24 15:05 raffaelgyr

@raffaelgyr Thank you for the suggestion! To further understand the use case, would this information mostly be useful for debugging or would you use it to drive some behavior in your app?

emawby avatar May 23 '24 19:05 emawby

I guess this counts as debugging.

raffaelgyr avatar May 24 '24 06:05 raffaelgyr

Hi @raffaelgyr — thanks for the feedback, and sorry for the delayed follow-up.

You’re right that the SDK doesn’t currently expose a public API for whether a OneSignal-created Android notification channel is enabled. That said, Android itself already provides this, so you can check it in-app today without waiting on an SDK change.

Workaround: check channel state with Android APIs

On Android 8.0+ (API 26+), a channel is disabled when its importance is IMPORTANCE_NONE:

fun isNotificationChannelEnabled(context: Context, channelId: String): Boolean {
    val notificationManager =
        context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

    // App-level notifications disabled
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
        && !notificationManager.areNotificationsEnabled()
    ) {
        return false
    }

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        return true
    }

    val channel = notificationManager.getNotificationChannel(channelId)
        ?: return true // channel not created on this device yet

    return channel.importance != NotificationManager.IMPORTANCE_NONE
}

Finding the correct channel ID

Use the on-device channel ID (not just the display name):

How the category was created Channel ID to check
OneSignal dashboard Android Notification Category The category’s android_channel_id from Settings → Push & In-App → Android Notification Channels (commonly prefixed with OS_)
No category set on the notification fcm_fallback_notification_channel (shown as Miscellaneous)
Restored notifications after force-quit restored_OS_notifications
Channel created in your app code The ID you created, referenced via existing_android_channel_id

To discover exactly what’s on a device:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    val notificationManager =
        getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

    for (channel in notificationManager.notificationChannels) {
        Log.d(
            "OneSignalChannelDebug",
            "id=${channel.id}, name=${channel.name}, " +
                "importance=${channel.importance}, " +
                "enabled=${channel.importance != NotificationManager.IMPORTANCE_NONE}"
        )
    }
}

Guide users to re-enable a disabled channel

fun openChannelSettings(context: Context, channelId: String) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return

    val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS).apply {
        putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
        putExtra(Settings.EXTRA_CHANNEL_ID, channelId)
    }
    context.startActivity(intent)
}

Suggested debugging flow for “user isn’t receiving notifications”

  1. Confirm the subscription is Subscribed in the OneSignal dashboard.
  2. Confirm app-level notification permission is enabled (OneSignal.Notifications.permission / system notification settings).
  3. Confirm the message’s Android category / android_channel_id matches the channel you expect.
  4. On the device, check that channel’s importance is not IMPORTANCE_NONE.
  5. If no category was set, specifically check Miscellaneous (fcm_fallback_notification_channel).
  6. On Samsung devices (especially One UI 6.1+), check whether categories were auto-disabled by the OS.
  7. If needed, capture a verbose OneSignal debug log while reproducing: Getting a Debug Log.

Also useful via adb:

adb shell cmd notification list_channels <your.package.name>

We’ll keep this enhancement request open internally. Internally the SDK already considers channel enablement when displaying notifications, but a public helper would make this easier for apps doing in-product troubleshooting. In the meantime, the native Android APIs above should unblock your use case.

abdulraqeeb33 avatar Aug 05 '26 14:08 abdulraqeeb33

We've updated our documentation to share more details on how this can be done: https://documentation.onesignal.com/docs/en/android-notification-categories#check-whether-a-category-is-enabled-on-the-device

jfishman1 avatar Aug 26 '26 15:08 jfishman1